Page 1 of 1

[0.9.3] CTD when using pointer to method of LuaObject

Posted: Tue Mar 18, 2014 11:31 am
by drs9999
So I have this weird bug somewhere in my new mod that results in a crash to desktop.

Weird thing about it is that it just appears every now and then.

Steps to reproduce:
1) download the zip that includes savegame and the related wip-mod ( I also use treefarm + anti-pollution, but they should not have any influence here)
2) load the save
3) wait approx 10 seconds

4a) if a message is printed => bug did not appear, try again :D
4b) else, ctd

download:
https://www.dropbox.com/s/figv2grtuvgv01u/BR.zip

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 12:28 pm
by kovarex
Thank you for the report, the problem is in the usage gp (pointer to method to game.player.print), we can try to fix it to not crash, or at least give better error.
Until than, I advice using game.player.print instead of gp

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 12:42 pm
by drs9999
Interesting , I did not expect that this is the reason. Avoiding it is so easy.


So does it affect only the pointer to the print-function or function-pointer in general?

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 1:27 pm
by kovarex
Function pointers are tricky in general. The problem is, that this was pointer to function of factorio Lua Object. The game object is persistant so the gt works, but the player object is created inside the construction game.player and removed soon later, so the pointer to the function becomes invalid.

Pointers to lua functions are possible, but can't be persistent (stored in global).

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 1:32 pm
by AlexPhoenix
kovarex, so none of the actions from Lua must not crash the game?

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 3:07 pm
by kovarex
AlexPhoenix wrote:kovarex, so none of the actions from Lua must not crash the game?
We would like it to work that way yes :)

Re: [0.9.3] CTD caused by bug in modscript

Posted: Tue Mar 18, 2014 6:00 pm
by kovarex
Ok, so we decided that we will not fix it now, as it is quite complicated issue to fix, with possible overhead, so we will put this to known issue and get back to it when people using custom scripts to crash other in multiplayer starts to be issue :)
Until then, avoid using pointers to functions of Lua objects.