Articles on: Garry's Mod

Crash Handler

What is Physgun Crash Handler

Physgun Crash Handler is a module of Physgun Utils that gives you the ability to get low level information about crashes, recover from them, and prevent them.

Some key notes:
You can find the configuration file in the Physgun Utils tab on your game panel
You can use the Lua API to greatly extend the ability's of the crash handler, default handlers will be released at a later date.


Detect Infinite Loops in Lua
Detect Segmentation Faults
Detect Lua Stack Over/Underflow
Detect IVP Hangs
Detect Crashes in external modules
Recover From Crashes
Crash Screen

Crash Recovery

The crash handler has the ability to rollback the game a few frames if a crash occurs, this can recover from Segfaults, Lua Loops, and more.
It is enabled by default, but can be replaced with the crash screen recovery method by adjusting the settings in the Physgun Utils tab.

This is very advanced and still in constant development, and can result in undefined behavior due to the nature of rolling back the game.

Crash Screen

The crash screen is fully customizable via lua, it is located in lua/autorun/crashphys.lua. To restore the default one, just delete the file.
The crash screen will automatically reconnect players when your server is fully back online after a crash that was detected by the crash handler.

If you are on a Phsygun dedicated server, you will need to request a custom Instance ID to add to your configuration, Open a ticket to get this.

Creating a custom Crash Screen

To create a custom crash screen, you can edit the file located in lua/autorun/crashphys.lua.

It is recommended to only edit the DrawCrashScreen function, edit the rest at your own risk as there is minimal error handling!

Developer API Functions

PhysgunCrashHandler.RestartWithCrashScreen() Restarts the server and dispatches the crashscreen payload to auto-reconnect players.
PhysgunCrashHandler.SetIVPSimulationToggle(bool toggleState) Toggles IVP simulation entirely, allows you to disable physics simulation
PhysgunCrashHandler.GetIVPSimulationToggle() -> number Returns the current toggle state of IVP simulation
PhysgunCrashHandler.SetIVPUpdateInterval(number updateTime) Sets how often to run a IVP simulation in seconds (default 0.01)
PhysgunCrashHandler.GetIVPUpdateInterval() -> number Returns the current IVP simulation time

Developer Hooks

Physgun:CrashHandler:RecoveredFromSegmentationFault Called after the crash handler recovers the Lua state and engine from a segfault
hook.Add("Physgun:CrashHandler:RecoveredFromSegmentationFault", "HookID", function()
	print("Recovered from segmentation fault")
	-- your logic here

Physgun:CrashHandler:RecoveredFromInfiniteLoop Called after the crash handler recovers the Lua state and engine from a infinite loop
hook.Add("Physgun:CrashHandler:RecoveredFromInfiniteLoop", "HookID", function()
	print("Recovered from infinite loop")
	-- your logic here

Physgun:CrashHandler:IVPSimulationTookLong Called if IVP takes longer then 30ms for a single simulation
hook.Add("Physgun:CrashHandler:IVPSimulationTookLong", "HookID", function(time)
	print("IVP Simulation took " .. time)
	-- your logic here

Updated on: 08/01/2024

Was this article helpful?

Share your feedback


Thank you!