Page 1 of 1

Crash by writing in readonly value

Posted: Thu Nov 08, 2018 12:57 pm
by Hermios
Hi,
I develop a new mod, and trid -by mistake - to write in readonly values (i.e. entity.train and entity.train.status).
As a consequence, instead of displaying a little message, close the current game and let me reload it immediatly, the soft crashed.
Attached the log of the crash.
Thanks

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 10:54 am
by Rseding91
It looks like you tried to write to the variables during an event - possibly train created?

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 11:15 am
by Hermios
Hi,
I confirm that my code was wrong. My point is, it shouldn't crash, just display a message. Since, I had other issues, like writing a status of a train, adding an attribute to a LuaEntity that doesn't exist, with the same result: Crash of Factorio, instead of displaying a nice, friendly message and letting me try again.
Said otherwise, Factorio overreacts :)
Thanks

Niko

P.S: The event is raised by a combination of keys, and the purpose is to destroy entities to recreate them with a new picture.

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 11:26 am
by Rseding91
Yes, it's meant to show an error and put you back on the main menu. However, I'm trying to figure out how it crashed instead. Based off the stack trace in the log file you uploaded I'm speculating your code was running inside of some train related event when it errored?

And as such, it left the train in a partially invalid state and crashed later trying to use the invalid train?

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 12:51 pm
by Hermios
Sorry, I misunderstood your point.
I just made a test by removing every other mod related to trains (This one only reacts on combination of keys) and... same crash (In my example, this is because I try to iterate on a nil value). So this has nothing to do with events for trains. However, when this event is raised, a locomotive is destroyed and a new one is created, with my character in it. Besides, when I did the same with other vehicles (tank and car), no such crash.
So it is probably related to trains, at the end of the day.

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 12:52 pm
by Rseding91
Can you upload a simple mod + steps that reproduces the issue?

Re: Crash by writing in readonly value

Posted: Fri Nov 09, 2018 12:57 pm
by Hermios
Attached the mod, and my sandbox game.
Just type "SHIFT+I", which triggers the event, and here comes the crash!

Re: Crash by writing in readonly value

Posted: Sun Nov 11, 2018 3:39 pm
by Rseding91
Thanks for the save and easy steps to reproduce it. It's now fixed for 0.17.

Re: Crash by writing in readonly value

Posted: Sun Nov 11, 2018 3:42 pm
by Hermios
Great, you are aweseome guys!
Thanks