[BUG] physenv.AddSurfaceData is broken

This has been a longstanding issue for me but I feel it’s worth one last attempt to get a fix. I should point out that this bug occurs on both the standard “live” version of Gmod and the Dev branch on steam.

Basically the lua function physenv.AddSurfaceData can only be used once. All subsequent attempts to use the function don’t appear to work, the surface data is not properly loaded and this causes crashes.

For example, this code works perfectly:


physenv.AddSurfaceData([[


"cartire"
{
    "base"        "rubber"
    
    "friction"    "1.2"
    "elasticity"    "3"
    "density"    "500"
}


"slidingcartire"
{
    "base"        "rubber"
    
    "friction"    "1"
    "elasticity"    "3"
    "density"    "500"
}


"trucktire"
{
    "base"        "rubber"
    
    "friction"    "5.0"
    "elasticity"    "3"
    "density"    "500"
}


"slidingtrucktire"
{
    "base"            "rubber"


    "friction"        "2.2"
    "elasticity"    "3"
    "density"    "500"
}
]])

In the above case both the truck and car drive as intended and there are no crashes when attempting to use the handbrake, everything works perfectly.

However if you split the code up into blocks or separate files like this:


physenv.AddSurfaceData([[


"cartire"
{
    "base"        "rubber"
    
    "friction"    "1.2"
    "elasticity"    "3"
    "density"    "500"
}


"slidingcartire"
{
    "base"        "rubber"
    
    "friction"    "1"
    "elasticity"    "3"
    "density"    "500"
}
]])
physenv.AddSurfaceData([[


"trucktire"
{
    "base"        "rubber"
    
    "friction"    "5.0"
    "elasticity"    "3"
    "density"    "500"
}


"slidingtrucktire"
{
    "base"            "rubber"




    "friction"        "2.2"
    "elasticity"    "3"
    "density"    "500"
}
]])

This causes the second vehicles surface properties to load incorrectly, in this case the truck. This means that when you attempt to use the handbrake it will crash the game. Interestingly if you use the cars handbrake this does not crash the game, the first set of surface properties are loaded properly. If you change the order so the trucks surface properties are listed first will cause the car to crash the game instead.

I find this bug very limiting because it makes it impossible to have multiple separate vehicle addons installed and working at the same time if they both rely on custom surface properties. This currently forces me to release my vehicle pack as a single large download which I would prefer not to do. There are workarounds like having the surface properties be part of a “base” pack and forcing people to download that before they download separate vehicles as separate workshop addons but it’s not foolproof.

This also limits other workshop vehicle makers and mappers/modellers wanting to improve their content using physenv.AddSurfaceData functions because of this bug.

Can this be fixed? Or perhaps would it be possible to roll back to the old surfaceproperties .txt system? (Why was it replaced in the first place?)

Also I humbly apologise if it turns out that there is a simple syntax error, or I missed a () or a or whatever in order to properly close a line and it turns out that this was the only problem but I have near enough zero coding knowledge, I have simply been using the code given to me here for the last couple of years. The Garry’s Mod Wiki doesn’t give any examples for physenv.AddSurfaceData functions.

I’m not one to bump threads, but I am interested in getting this issue looked at. Hope someone could take a look at it. It’s a pain the ass to work on vehicles in Garry’s Mod, otherwise.

Okay I’ve put up a Github issue here: https://github.com/Facepunch/garrysmod-issues/issues/1821 and I have done a little more testing and updated the bug desciption in the OP slightly where I had made a mistake.

Also on a sidenote trying to edit posts on Facepunch has become really difficult, since when have we had to answer a captcha? and also why does it delete the actual post? I had to copy everything back into the text field from the thread page. and why does it keep adding extra line breaks?