NPE with Chisels and Bits
sargunv opened this issue ยท 7 comments
Forge: 1.11-13.19.1.2189
The game crashed while I was chiseling a block (Chisels and Bits mod) in creative mode. I was chiseling for a while before it happened, so it's possible the chisel mod had nothing to do with it. I'm reporting here since the stack trace shows a NPE in Hwyla:
Stack trace:
java.lang.NullPointerException: Unexpected error
at mcp.mobius.waila.overlay.RayTracing.getIdentifierItems(RayTracing.java:181)
at mcp.mobius.waila.overlay.RayTracing.getIdentifierStack(RayTracing.java:88)
at mcp.mobius.waila.overlay.RayTracing.getTargetStack(RayTracing.java:59)
at mcp.mobius.waila.overlay.DecoratorRenderer.onRenderWorldLast(DecoratorRenderer.java:26)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_44_DecoratorRenderer_onRenderWorldLast_RenderWorldLastEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185)
at net.minecraftforge.client.ForgeHooksClient.dispatchRenderLast(ForgeHooksClient.java:166)
at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at Reflector.callVoid(Reflector.java:342)
at net.minecraft.client.renderer.EntityRenderer.func_175068_a(EntityRenderer.java:1887)
at net.minecraft.client.renderer.EntityRenderer.func_78471_a(EntityRenderer.java:1573)
at net.minecraft.client.renderer.EntityRenderer.func_181560_a(EntityRenderer.java:1350)
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:1075)
at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:370)
at net.minecraft.client.main.Main.main(SourceFile:124)
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:483)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Let me know if there's any other info you need.
I've had this reported to me before on Discord. It only seems to occur when turning a C&B block back into the original block. From what I could tell, nothing was causing it on my end. I'll take another look tonight, though.
I've done some further testing.
I had no issues turning a C&B block back to the original. Looks like I can make the crash happen every time by using the drawn region chisel mode. This happens regardless of whether the Hwyla overlay is enabled, but removing Hwyla from the mods folder resolves the crash.
Fixed by changing in RayTracing.getIdentifierItems
ItemStack pick = mouseoverBlock.getPickBlock(world.getBlockState(pos), target, world, pos, player);//(this.target, world, pos, player);
if (!pick.isEmpty())
items.add(pick);
to
ItemStack pick = mouseoverBlock.getPickBlock(world.getBlockState(pos), target, world, pos, player);//(this.target, world, pos, player);
//noinspection ConstantConditions
if (pick != null && !pick.isEmpty())
items.add(pick);
If you like, I can make a PR.
The thing is, ItemStack is Nonnull in 1.11. That check shouldn't be needed. That would be a bandaid, not a solution.
You're right, this should be reported to C&B too so it can be fixed properly there.
However, there's no guarantee that every mod out there is going to respect the nonnull constraint properly. I feel like it's a good idea for a mod like this to expect those cases. What about a try/catch somewhere that would log these unexpected cases instead of crashing the game?
EDIT:
Ignore what was here before this edit. I was just very confused about something. I'll report the bug to C&B tonight, but I think you should still consider adding some failsafe to prevent a total crash if another mod isn't following the nonnull spec properly.
A failsafe for this issue would only prolong the amount of time mods are broken. A commonly used mod breaking all the time would cause other authors to fix their code properly.
A try/catch
would also not be ideal as they cause a considerable amount of overhead.