Physics Mayhem: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 23: Line 23:
* [https://bugs.alliedmods.net/show_bug.cgi?id=6348 Technical bug report (Alliedmodders bugzilla)]
* [https://bugs.alliedmods.net/show_bug.cgi?id=6348 Technical bug report (Alliedmodders bugzilla)]
* [https://web.archive.org/web/20190406220848/https://forum.facepunch.com/gmoddev/likl/Crazy-Physics-cause-found/1/ Garry's Mod report (Facepunch forums, archived)]
* [https://web.archive.org/web/20190406220848/https://forum.facepunch.com/gmoddev/likl/Crazy-Physics-cause-found/1/ Garry's Mod report (Facepunch forums, archived)]
[[Category:VPhysics]]

Latest revision as of 20:49, 8 August 2025

Physics Mayhem is a physics engine bug present in all Source branches using Havok except Counter-Strike: Global Offensive.

If an entity's solidity type or collision group is changed manually (for example, by using addoutput solid 2 with I/O or NetProps.SetPropInt(entity, "m_CollisionGroup" in VScript), internal cached physics information will not be updated. Eventually, Havok can implode attempting to run the simulation with the stale information when this entity comes in contact with other objects. Effects range from unpredictable, bouncy prop behavior to all VPhysics-simulated objects falling through all geometry. This bug is global and once it occurs, it is unrecoverable. The only fix is a full server restart.

To avoid this bug, do not set the solid or collision group fields manually. Instead, use the game's native routines to handle this. In VScript, this is SetSolid and SetCollisionGroup. In SourceMod, use CollisionRulesChanged.

The technical reason for this bug is a hack introduced for E3 2003 involving unused collisions. A global boolean variable is set to true when a specific edge case happens, intended to defer collision code later temporarily. Unfortunately, the boolean is never set back to false, and this causes all collisions to permanently fail.

Tip.pngTip:Offset for this boolean variable on Source 2013 Multiplayer Source 2013 Multiplayer into vphysics.dll is 0x73CC0 (for monitoring or patching purposes). On 32-bit Garry's Mod (64-bit is not affected as it uses Counter-Strike: Global Offensive VPhysics), the offset is 0xD7EFC.
Note.pngNote:Other than changing the boolean, it is also possible to recover from this at runtime by reloading the physics engine with the PhysSwapper plugin.

Patch for 32-bit Garry's Mod

Using a hex editor, open vphysics.dll and search for the hex sequence
FE 02 7C EC 33 F6

Replace the bytes after that sequence to
8D 05 FC 7E 0D 10 90 89 35 F8 7E 0D 10 80 38 00 C6 00 00 74 0C 90 90 90 90 90.

This will automatically set the boolean to false after a collision failure occurs, therefore making the physics engine recover.

External Links