Nucler reactor crash because of floating point errors
Gaider10 opened this issue ยท 1 comments
If you put a fuel rod in a hatch, wait for a bit and take it out there is a chance that its neutron absorbtion will stay at -0.0 in the reactor GUI, if you then place a full durability large carbon plate in the hatch the game will crash
This happens because because since 9371dfb IntegerHistoryComponent
doesn't recalculate the average every tick but instead updates it using a formula introducing floating point errors that can make the average negative after the value rises and then drops to zero again, for example if the value is 1 for 3 ticks and then stays 0 the average stabilizes to -3.469446951953614e-18, and when you put a large carbon plate in such a hatch https://github.com/AztechMC/Modern-Industrialization/blob/master/src/main/java/aztech/modern_industrialization/nuclear/NuclearAbsorbable.java#L92-L103 tries to add 1 durability to it every tick which causes a crash when it goes over the plate's max durability
Instead IntegerHistoryComponent
should probably keep the sum of all the values as an integer and only divide it when getting the average to prevent it from becoming negative when none of the values are negative