Placebo

Placebo

160M Downloads

ArrayIndexOutOfBoundsException

LlubNek opened this issue ยท 17 comments

commented

When crafting certain items using a shapeless recipe (crafting table -> crafting station in my case, but it varies), minecraft fails to lookup the recipe output and, if I check the log, I find an error like this:

Error executing task on Server
java.lang.ArrayIndexOutOfBoundsException: 4
	at it.unimi.dsi.fastutil.ints.IntArrayList$1.nextInt(IntArrayList.java:500)
	at it.unimi.dsi.fastutil.ints.IntIterator.next(IntIterator.java:43)
	at it.unimi.dsi.fastutil.ints.IntListIterator.next(IntListIterator.java:102)
	at it.unimi.dsi.fastutil.ints.IntListIterator.next(IntListIterator.java:30)
	at java.util.AbstractCollection.toArray(AbstractCollection.java:141)
	at java.util.List.sort(List.java:477)
	at net.minecraft.item.crafting.Ingredient.func_194139_b(Ingredient.java:97)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:40)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:15)
	at net.minecraft.item.crafting.IRecipeType.func_222148_a(SourceFile:29)
	...

With Polymorph installed I'll also get this:

Attempted to craft using [1 oak_planks, 1 air, 1 air, 1 air] but an error occurred while fetching recipes!
java.lang.ArrayIndexOutOfBoundsException: 4
	at it.unimi.dsi.fastutil.ints.IntArrayList.add(IntArrayList.java:260)
	at net.minecraft.item.crafting.Ingredient.func_194139_b(Ingredient.java:94)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:40)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:15)
	at net.minecraft.item.crafting.IRecipeType.func_222148_a(SourceFile:29)
	...

and later:

Attempted to craft using [1 air, 1 air, 1 crafting_table, 0 air] but an error occurred while fetching recipes!
java.lang.ArrayIndexOutOfBoundsException

This can also result in item duplication for the ingredients.

This also happens for logs->planks and plank->button

As you stated in your comments on curseforge this may be related to a broken recipe in another mod, but this seems to break every shapeless recipe, and provides no information about which recipe is causing the problem.

latest.log

Placebo-1.15.2-3.0.2.jar
polymorph-FORGE-1.15.2-0.3.jar
forge-31.2.30
minecraft 1.15.2

commented

I don't know what mod is causing the problem, it doesn't occur in any of the major 1.15 modpacks, but you can use this jar to determine what recipe is causing the issue https://github.com/Shadows-of-Fire/Placebo/releases/tag/3.1.0-recipedebug

commented

What makes you think it doesn't occur in any of the major 1.15 modpacks? We get this issue reported several times per day on the Valhelsia Discord for Valhelsia 2. I just haven't been able to track down the cause yet due to illness, and the crash reports + logs are essentially identical so don't provide any additional information (prior to you releasing that JAR there, of course).

It's why I asked about disabling the changes that Placebo makes like the CurseForge description still says is possible. I wanted to rule it out as an issue entirely if I could so that I could narrow down the possible causes.

commented

Try as I might I cannot get it to happen on Valhelsia, and if it was happening in ATM5, drunk would be yelling at me nonstop, which is what precedes that statement.

commented

Pretty common example: https://paste.ee/p/e9U8Z

I try not to yell at people, especially as in this case as I have no idea who I should be yelling at and haven't had the energy to deal with things in depth yet. My only frustration with you was the inaccurate CurseForge description leading me to trying to figure out how to disable the functionality for far too long before giving up.

For the most part, people say they're trying to craft simple things like planks from logs. This one here: https://paste.ee/p/1vGLJ was somebody who said they started a new world, harvested some birch logs, and crashed as soon as they opened their inventory. After updating to the version of Polymorph that prevents the game crashing they were unable to convert birch logs into birch planks in their inventory crafting screen.

commented

I'm having a hard time getting this bug to show up when I want it to. I've installed your debug mod though, and when it turns up again I'll report it.

If you're right about the cause, this should be easy enough to reproduce (same mods, same recipes, same bug), but it seems to be pretty fickle.

commented

I think perhaps the most confusing part is this: https://paste.ee/p/e9U8Z#s=0&l=6043
Where this is happening, the array should've already been resized to make this effectively impossible. I'm starting to wonder if this is even a recipe or mod issue, as it may be an issue with the mojang-provided FastUtil library...

Until someone can mark a recipe as erroring with this, I can't really determine the cause. There's also a possibility that it's something more complex such as a JVM internal issue based on the type being run, but that would be really weird.

The only other place this functionality is used is in the recipe book, and with that being disabled in every modpack, this issue won't ever pop up there.

commented

I'm going to make a prediction now based on where I have seen issues with FastUtil before (and where it's being called in the exception you linked to): This is some annoying concurrency issue, since FastUtil isn't thread safe.

commented

Hm, that is.... theoretically possible?
Question is what is doing recipe ops like that off the main thread in the first place.

Technically it would be avoidable by invoking getValidItemStacksPacked immediately after the recipes are constructed (so that the initialization is never in a race condition)

commented

Looking closer, I'm thinking more and more like that's the issue. See that log again - there's two threads in play, the Server Thread and the Render Thread. The former is handling the CClickWindowPacket and the latter is handling Polymorph's various methods.

commented

I also feel a touch stupid for not thinking of it earlier, given how many PRs I've submitted recently regarding concurrency issues.

commented

I can't promise that fixes it, but if it is a race condition, it should.

commented

If it's on CurseForge in the near future (edit: looks like it already is, great!), then I will know soon enough, since we're pushing the next Valhelsia release as soon as we can... if it works then the reports will stop coming. :)

Appreciate the quick fix.

commented

not fixed...

Error executing task on Server
java.lang.RuntimeException: The recipe silents_mechanisms:metals/electrum_nuggets has thrown an exception while matching, this is a bug in the owning mod.
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:49)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:15)
	at net.minecraft.item.crafting.IRecipeType.func_222148_a(SourceFile:29)
	...

Attempted to craft using [1 air, 1 air, 1 spruce_log, 1 air] but an error occurred while fetching recipes!
java.lang.RuntimeException: The recipe silents_mechanisms:metals/electrum_nuggets has thrown an exception while matching, this is a bug in the owning mod.
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:49)
	at shadows.placebo.recipe.FastShapelessRecipe.func_77569_a(FastShapelessRecipe.java:15)
	at net.minecraft.item.crafting.IRecipeType.func_222148_a(SourceFile:29)
	...

latest.log

mc 1.15.2
forge-31.2.30
Placebo-1.15.2-3.1.0.jar
polymorph-FORGE-1.15.2-0.3.jar
SilentMechanisms-1.15.2-0.7.6+57.jar

Looking at the recipe json in SilentMechanisms, I really don't see any problems, but I'm not great with datapacks yet:

{
  "type": "minecraft:crafting_shapeless",
  "ingredients": [
    {
      "tag": "forge:ingots/electrum"
    }
  ],
  "result": {
    "item": "silents_mechanisms:electrum_nugget",
    "count": 9
  }
}
commented

You're not using the release that was pushed to curse, which is the one that fixes the problem

commented

yeah, just noticed both the debug version I manually installed and the curseforge release were in the mods folder and neither disabled. Not really sure why that didn't give me an error during startup.

commented

Hey @Vaelzan , in 1.15 have you noticed any shapeless recipes being broken (to the degree of what's happening in #16)

commented

No, 1.15 is currently fine from what I can tell after the fix a while back. Everybody yelling at us recently about recipe issues has been talking about 1.16.1.