Is there a way to backtrace an event?

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
zebediah49
Fast Inserter
Fast Inserter
Posts: 119
Joined: Fri Jun 17, 2016 8:17 pm
Contact:

Is there a way to backtrace an event?

Post 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?

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Is there a way to backtrace an event?

Post by Nexela »

Event id 0 is on_tick

Post your code and I can peek at it.

zebediah49
Fast Inserter
Fast Inserter
Posts: 119
Joined: Fri Jun 17, 2016 8:17 pm
Contact:

Re: Is there a way to backtrace an event?

Post 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.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Is there a way to backtrace an event?

Post 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.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Is there a way to backtrace an event?

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Modding discussion”