Opening the Formulaic assembler crashes the game
quinchs opened this issue ยท 9 comments
Summary
When opening the Formulaic assemblers gui it crashes the game.
Steps to reproduce:
- Place formulaic assembler
- Attempt to right click
Version (make sure you are on the latest version before reporting):
Forge: 36.1.18
Mekanism: v10.1 (build of the current v10.1 branch)
Crash message
The game crashed whilst rendering screen
Error: java.lang.ArrayIndexOutOfBoundsException: 9
Exit Code: -1
Crash log
This is the culprit function that throws the exception
@Override
protected ItemStack checkValidity(int slotIndex) {
int i = slotIndex - 19;
if (i >= 0 && tile.formula != null && tile.formula.isValidFormula()) {
ItemStack stack = tile.formula.input.get(i);
if (!stack.isEmpty()) {
Slot slot = menu.slots.get(slotIndex);
//Only render the "correct" item in the gui slot if we don't already have that item there
if (slot.getItem().isEmpty() || !tile.formula.isIngredientInPos(tile.getLevel(), slot.getItem(), i)) {
return stack;
}
}
}
return ItemStack.EMPTY;
}
tile.formula.input.get(i);
throws out of bounds
Wrapping everything in a try catch, then logging the exceptions result in this
if (i >= 0 && tile.formula != null && tile.formula.isValidFormula()) {
try {
ItemStack stack = tile.formula.input.get(i);
if (!stack.isEmpty()) {
Slot slot = menu.slots.get(slotIndex);
// Only render the "correct" item in the gui slot if we don't already have that
// item there
if (slot.getItem().isEmpty()
|| !tile.formula.isIngredientInPos(tile.getLevel(), slot.getItem(), i)) {
return stack;
}
}
} catch (Exception x) {
System.out.println("Caught " + x.toString() + "\nIndex was " + i + ". input size: "
+ tile.formula.input.size() + ". Slot size: " + menu.slots.size());
}
}
[25Jun2021 00:35:50.796] [Render thread/INFO] [STDOUT/]: [mekanism.client.gui.machine.GuiFormulaicAssemblicator:checkValidity:121]: Caught java.lang.ArrayIndexOutOfBoundsException: 9
Index was 9. input size: 9. Slot size: 73
[25Jun2021 00:35:50.797] [Render thread/INFO] [STDOUT/]: [mekanism.client.gui.machine.GuiFormulaicAssemblicator:checkValidity:121]: Caught java.lang.ArrayIndexOutOfBoundsException: 10
Index was 10. input size: 9. Slot size: 73
[25Jun2021 00:35:50.814] [Render thread/INFO] [STDOUT/]: [mekanism.client.gui.machine.GuiFormulaicAssemblicator:checkValidity:121]: Caught java.lang.ArrayIndexOutOfBoundsException: 9
Index was 9. input size: 9. Slot size: 73
[25Jun2021 00:35:50.814] [Render thread/INFO] [STDOUT/]: [mekanism.client.gui.machine.GuiFormulaicAssemblicator:checkValidity:121]: Caught java.lang.ArrayIndexOutOfBoundsException: 10
Index was 10. input size: 9. Slot size: 73
My theory is that the GuiMekanism
is calling the validate function for the crafting grid slots, the formula slot, and the energy slot. The index's' max value is 11 and the grid only has 9 slots.
The GuiMekanism
class calls the checkValidity function for every slot thats marked as ContainerSlotType.VALIDITY
, I would assume the enery input slot and the crafting formula slot have their slot type set as VALIDITY therfor the checkValidity
function is called for them as well
// https://github.com/mekanism/Mekanism/blob/v10.1/src/main/java/mekanism/client/gui/GuiMekanism.java#L422
if (slotType == ContainerSlotType.VALIDITY) {
int index = i;
guiSlot.validity(() -> checkValidity(index));
}
It looks like the code in checkValidity
does not account for the energy slot and the crafting slot, it only checks the crafting input slot
I believe the issue is just int i = slotIndex - 19;
is wrong, but I need to look at it further when I get the chance. At one point if memory serves we moved the index of the energy slot so that shift clicking doesn't prioritize it with things like redstone, and my guess is we just forgot to update that line to be like slotIndex - 20
or something
I mean the correct thing is to change how i is calculated to be subtracted by two further so that isIngredientInPos also gets called with the proper value as well