Page 1 of 1
Is there a way to backtrace an event?
Posted: Fri May 05, 2017 11:54 pm
by zebediah49
I'm trying to fix up a mod from 0.14 to 0.15, and am getting a "Exception at tick XXXX: Received event 0 has not been defined." I've been using a whole bunch of 'print's to try to track this down, and it's not working as well as I'd like. (Specifically, I've instrumented all of the `raise_event`s, and none of them are throwing the event ID 0).
Under normal circumstances I'd just fire up GDB and trace back up to whatever function sent that event, but -- I have no idea if/how a debugger can be used for Factorio mods.
So yeah, does anyone have any methods for debugging on this? Or am I just stuck with huge piles of 'print's?
Re: Is there a way to backtrace an event?
Posted: Sat May 06, 2017 12:39 am
by Nexela
Event id 0 is on_tick
Post your code and I can peek at it.
Re: Is there a way to backtrace an event?
Posted: Sat May 06, 2017 3:00 am
by zebediah49
I'm trying to retrofit mknejp's
Wireless Charging (+
Wireless Charging Lib).
I believe the offending call is in Wireless Charging/src/main.lua:81
Code: Select all
function on_charging_stopped(event)
.....
if(next(charging_accumulator_grids) == nil) then
script.on_event(defines.events.on_tick, nil) --this line causes the issue
end
given that commenting out that particular line results in it not throwing the error. This seems weird though, because shouldn't that be the valid way of de-registering the on-tick event? Did something about that change in 0.15?
For comparison, the on_charging_started uses a
Code: Select all
script.on_event(defines.events.on_tick, on_tick)
to register the charging-handling code, and that seems to work fine.
Re: Is there a way to backtrace an event?
Posted: Mon May 08, 2017 7:56 am
by bobingabout
I'm not sure what you're trying to do here, but, that does look... wrong.
Are you trying to delete the on_tick event on the fly? if so, a better solution would be to put that check in the on_tick event, and drop out if you're don't need to do anything.
Re: Is there a way to backtrace an event?
Posted: Mon May 08, 2017 2:48 pm
by Rseding91
bobingabout wrote:I'm not sure what you're trying to do here, but, that does look... wrong.
Are you trying to delete the on_tick event on the fly? if so, a better solution would be to put that check in the on_tick event, and drop out if you're don't need to do anything.
Deleting events on the fly is valid (although easy to get wrong and cause desyncs).
Can you post the mod(s) and how you get the error to happen? Looking at where that error comes from there might be a problem with how the game fires events. If I'm reading this correctly: if during an event loop a mod un-registers from an event through a remote call it will produce this error.