justarandomgeek / vscode-factoriomod-debug

Factorio Mod Tool Kit
Other
97 stars 21 forks source link

pcall(script.on_event, "on_load", ...) triggers debugger to hook #80

Open BurninSun opened 1 year ago

BurninSun commented 1 year ago

Using pcall(script.on_event, ...) with "on_load", "on_init" or "on_configuration_changed" causes the debugger to hook those functions as if they were being registered even though they aren't registerable through script.on_event. Caused a crash with it at one point but can't remember what exactly I did.

Even doing it manually via: /c __space-exploration__ pcall(script.on_event, "on_load", function() end) causes an error in the debug console: Replacing existing "on_load handler" <Lua function @__space-exploration__/scripts/event.lua:587> with <Lua function =(dostring):1>

justarandomgeek commented 1 year ago

It doesn't actually hook anything special, it just records that it has seen them registered to try to make a better guess at names than just file location later when they're called. I'll see if I can work out how wrong entries there would cause a crash though...

BurninSun commented 1 year ago

If you're not looking at changing the functionality, I'll see if I can hunt down the crash. I think it was pcalling script.on_event with a nil function or some such but only in a certain circumstance.

It was a Lua crash, but the trace was all the way back to the debug adapter.