Reika_Mods_Issues icon indicating copy to clipboard operation
Reika_Mods_Issues copied to clipboard

[ReactorCraft] Crash caused by invalid item damage value on some nuclear waste

Open Konrad-Wszelaki opened this issue 2 years ago • 1 comments

Hi, I was testing out my brand new fission reactor when suddenly the game crashed, showing IndexOutOfBoundsException, and I'd rather lose my save due to the reactor melting down and not due to bugs. The same crash happens when I try to load the save again, so it's rather destructive (fortunately it happened on a copy of my save, since I was just testing the reactor) Crash report on pastebin: https://pastebin.com/kBiGjK79. Looking at the report and digging in ReactorCraft source code, the crash seems to have been caused by trying to get waste with damage value of 24, while there are only 18 types of waste. Right now it only happened once and might have been just some random error, but in case it's an actual bug and I just don't see what caused it I decided to create an Issue.

EDIT: it happened again with no obvious cause. Same exact error, I see no differences between the two logs (except for time of course), but here's the second crash log, just in case: https://pastebin.com/c73v8mtc

Konrad-Wszelaki avatar Sep 24 '22 18:09 Konrad-Wszelaki

TLDR: Java is a typed language. Use that fact to your advantage. -=-=-=- ...what did you even do...

From what I got from a quick glander at the source, waste items are never made without looking at the WasteManager, which should never ever give a waste id above 17 (18 items and counts from 0), let alone 24!

wait, it seems like Reika mixed up Isotopes and the WasteManager quite a bit, as some things, such as isItemValidForSlot(int, ItemStack) assume the damage value is an Isotope ID, but other things, such as getHalfLife(ItemStack), assume it's a waste ID and pass it through the waste manager first.

This probably went undetected for a long time as normally that would just result in either mixups of decay times, (such as waste not entering in the correct waste drum, or taking too long/not long enough), or mixups of decay types, which no-one really cares about.

But what if the isotope ID is so high, there's no valid waste ID?

Isotope number 25 is Gd155, which is a valid waste item, so I'm guessing somewhere in the code a waste got created with the Isotope ID and not the Waste ID (I can't find the exact location, but this seems likely, as the "add waste time to tooltip" method uses the Isotope ID), the Isotope ID got treated as the Waste ID, causing an out of bounds access, exploding the game.

And ladies and gentlemen, that's why enums are objects and not numbers

Paging @ReikaKalseki (again...) as this seems to be a serious mixup, and it's a mircacle it didn't catch fire sooner.

FavoritoHJS avatar Sep 29 '22 20:09 FavoritoHJS

This system got rewritten in v32, almost certainly fixing this.

ReikaKalseki avatar Jul 03 '23 23:07 ReikaKalseki