game.raise_event() is not protected from invalid entities.
Posted: Thu May 19, 2016 12:11 am
I remember Rsending(?) saying in the modding section that the game is capable of catching the situation, when one mod destroys entity passed to event handler.
I've kinda broke that...
If the event is raised not by the game but through script at the worst case you can get the following mysterious thing:
If you place stone furnace in that save, handlers from all three mods will print stuff to the screen.
If you place steel furnace, it will be destroyed by second handler and third one won't be called.
If you place turret - it will be destroyed by TurretRangeOnBuild mod, which will then create another dummy-turret and raise event with that one through game.raise_event() function, that dummy-turret will be destroyed by the ElectrifiedTurrets mod and here's where it breaks apart: on_entity_built event continues to handled with now invalid entity.
The mods are not reduced to relevant code but in TurretRangeOnBuild relevant lines are 27 - 50, in ElectrifiedTurrets - 31 - 53 and in WrenchFu - 11 - 16 (all in control.lua).
Weird thing is that if you comment out line 30 in TurretRangeOnBuild, that handles the error in that mod, then you'll get a proper backtrace.
I've kinda broke that...
If the event is raised not by the game but through script at the worst case you can get the following mysterious thing:
Screenshot
I've uploaded archive with three mods that do that together and the save set up for test.If you place stone furnace in that save, handlers from all three mods will print stuff to the screen.
If you place steel furnace, it will be destroyed by second handler and third one won't be called.
If you place turret - it will be destroyed by TurretRangeOnBuild mod, which will then create another dummy-turret and raise event with that one through game.raise_event() function, that dummy-turret will be destroyed by the ElectrifiedTurrets mod and here's where it breaks apart: on_entity_built event continues to handled with now invalid entity.
The mods are not reduced to relevant code but in TurretRangeOnBuild relevant lines are 27 - 50, in ElectrifiedTurrets - 31 - 53 and in WrenchFu - 11 - 16 (all in control.lua).
Weird thing is that if you comment out line 30 in TurretRangeOnBuild, that handles the error in that mod, then you'll get a proper backtrace.