Stormwind99 / FoodFunk

Minecraft mod: What is that funky smell in my backpack? Food spoils over time unless preserved. Configure any item to rot, any container to preserve items.
https://minecraft.curseforge.com/projects/food-funk
GNU Lesser General Public License v3.0
10 stars 8 forks source link

don't store null in NBTTagCompound #56

Closed phit closed 4 years ago

phit commented 5 years ago

Describe the bug You are trying to store null in NBT https://github.com/Stormwind99/FoodFunk/blob/master/src/main/java/com/wumple/foodfunk/capability/rot/Rot.java#L194

https://gist.github.com/phit/522ba594f8d9be034324441a7a2d5c45

causes issues like https://github.com/Stormwind99/FoodFunk/issues/41 https://github.com/Stormwind99/FoodFunk/issues/39

Stormwind99 commented 4 years ago

Do you have an easy way to duplicate the crash so I can test potential workarounds?

Stormwind99 commented 4 years ago

I haven't found where null in the NBT could be coming from.

In line 194, NBTTagCompound nbt = (NBTTagCompound)storage.writeNBT(Rot.CAPABILITY, this, null); the EnumFacing null is ignored (just an artifact of the interface required to be used). Rot.Capability should never be null, but I will add a check JIC. this should never be null also.

If something else bad has happened, the NBTTagCompound could theoretically be empty but not null. I'll add a null and !empty check around tag.merge(nbt); also.

If any of the above avoid the crash, it is probably evidence of something else wrong elsewhere (since none of these checks should be needed at this place in the code TMK).

If you have any additional insight, please let me know. Thanks!

Stormwind99 commented 4 years ago

Food Funk 4.9.6 and WumpleUtil 2.12.9 may have workarounds for this crash - can you try them both out?

Stormwind99 commented 4 years ago

And a question for IC2 devs and maybe Forge devs: Why is the IC2 mod triggering a capability serialization during client startup/mod initialization? That seems very bad - since things aren't initialized yet.

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from IndustrialCraft 2 (ic2)
Caused by: java.lang.IllegalArgumentException: Invalid null NBT value with key foodfunk:rot
    at net.minecraft.nbt.NBTTagCompound.func_74782_a(NBTTagCompound.java:85)
    at net.minecraftforge.common.capabilities.CapabilityDispatcher.serializeNBT(CapabilityDispatcher.java:123)
    at net.minecraft.item.ItemStack.func_77946_l(ItemStack.java:396)
    at ic2.core.recipe.RecipeInputItemStack.<init>(RecipeInputItemStack.java:22)
    at ic2.core.recipe.RecipeInputFactory.forStack(RecipeInputFactory.java:24)
    at ic2.core.block.machine.tileentity.TileEntityCanner.addBottleRecipe(TileEntityCanner.java:120)
    at ic2.core.block.machine.tileentity.TileEntityCanner.init(TileEntityCanner.java:77)
    at ic2.core.IC2.load(IC2.java:238)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:637)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
    at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)
    at net.minecraft.client.main.Main.main(SourceFile:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28))
Stormwind99 commented 4 years ago

I was able to duplicate this crash, and now after the mod compat workarounds in Food Funk 4.9.6 and WumpleUtil 2.12.9 it no longer crashes for me.