Thomasims / GCrash

Garry's Mod SIGSEGV handler to dump the Lua state
15 stars 5 forks source link

Handling map changes #3

Closed rylinj closed 4 years ago

rylinj commented 4 years ago

Conventionally you would think just hooking "ShutDown" and calling the stop command should allow it to switch maps normally however that doesn't appear to be the case. Is there anything else we should be doing prior to a map change?

Thomasims commented 4 years ago

Can you explain what you're trying to do and what is happening that you're not expecting here? I'm having a hard time understanding what the problem is and how it's related to this module.

rylinj commented 4 years ago

local enable_watchdog = true
local active_watchdog = false

local function startwatchdog()
    if not active_watchdog then
        gcrash.startwatchdog()
        active_watchdog = true
    end
end

local function stopwatchdog()
    if active_watchdog then
        gcrash.stopwatchdog()
        active_watchdog = false
    end
end

gcrash.sethandler( function( write )
    local function printline( s, ... ) write( string.format( tostring( s or "" ) .. "\n", ... ) ) end

    local i = 2 -- Only start at frame 2, we don't need the locals of this function
    local dbg = debug.getinfo( i )
    while dbg do
        printline( "Frame #%d:", i - 2 )

        for j = 1, 255 do
            local n, v = debug.getlocal( i, j )
            if not n then break end
            printline( "  %s = %s", tostring( n ), tostring( v ) )
        end

        printline( "" )
        i = i + 1
        dbg = debug.getinfo( i )
    end

end )

gcrash.crash = nil -- You can comment this out if you want to use it (to crash your server?)

if enable_watchdog then
    if GetConVar( "sv_hibernate_think" ):GetBool() then
        startwatchdog()
        print( "Starting gcrash watchdog..." )
    else
        hook.Add( "PlayerInitialSpawn", "gcrash_watchdogsleeper", function()
            startwatchdog()
            print( "Starting gcrash watchdog..." )
            hook.Remove( "PlayerInitialSpawn", "gcrash_watchdogsleeper" )
        end )
    end

    hook.Add( "ShutDown", "gcrash_shutdown", function()
        stopwatchdog()
    end )
end

We experienced segmentation faults using the default gcrash handler on map change, we attempted to resolve the issue by manually stopping the watchdog process before map changes as shown above. However, the issue persisted on subsequent map changes, only stopping with the above script commented out.

Thomasims commented 4 years ago

I've committed changes that should fix this issue, please report back if it is still present in release v0.3

rylinj commented 4 years ago

That appears to have resolved the issue, thank you for the help!