Page 1 of 1
[0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Posted: Sun Dec 03, 2017 2:23 am
by Mylon
When a logistic net has a negative amount of a good, using the API to get the amount the logistic network contains reports a ridiculously high number.
https://imgur.com/a/LBRdG
I'm not sure exactly how to reproduce the negative amount, but it seems like a case of trying to assign an unsigned int from a signed int.
Re: [0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Posted: Sun Dec 03, 2017 7:09 am
by Optera
Logistic network readout has a few caveats.
1) Items transported by robots are not shown in any readout.
2) Negative amounts happen because bots are scheduled to pick up their cargo capacity regardless of how much is in storage.
Together those can produce negative numbers quite often in networks with low storage amounts.
To me that looks like that window is displaying the values as unsigned 32bit or 64bit int while internally Factorio uses 32bit signed int.
You could possibly do something like
this to read the MSB as sign.
Re: [0.15.40] LuaLogisticNetwork.get_item_count(item) overflow
Posted: Sun Dec 03, 2017 2:48 pm
by Rseding91
Thanks for the report. This was fixed for 0.16 a few months ago.