MovingBlocks / Terasology

Terasology - open source voxel world
http://terasology.org
Apache License 2.0
3.69k stars 1.34k forks source link

ItemCommonSystem Null reference exception #2466

Open pollend opened 8 years ago

pollend commented 8 years ago

What you were trying to do

https://github.com/pollend/TerasologyMineSweeper

For my minesweeper mod I wanted mines to explode if you mine them. The problem is when you mine an explosive mine and attempt to pick up the blocks on the ground. The game will crash with this exception:

java.lang.NullPointerException
    at org.terasology.rendering.nui.layers.ingame.inventory.ItemCell$3.get(ItemCell.java:84)
    at org.terasology.rendering.nui.layers.ingame.inventory.ItemCell$3.get(ItemCell.java:79)
    at org.terasology.rendering.nui.layers.ingame.inventory.ItemIcon.getMesh(ItemIcon.java:130)
    at org.terasology.rendering.nui.layers.ingame.inventory.ItemIcon.onDraw(ItemIcon.java:72)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:368)
    at org.terasology.rendering.nui.layers.ingame.inventory.ItemCell.onDraw(ItemCell.java:111)
    at org.terasology.rendering.nui.layers.ingame.inventory.InventoryCell.onDraw(InventoryCell.java:99)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.layouts.FlowLayout.onDraw(FlowLayout.java:57)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.layouts.relative.RelativeLayout.onDraw(RelativeLayout.java:78)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.layers.hud.CoreHudWidget.onDraw(CoreHudWidget.java:60)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.layers.hud.HUDScreenLayer.onDraw(HUDScreenLayer.java:162)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawStyledWidget(CanvasImpl.java:406)
    at org.terasology.rendering.nui.internal.CanvasImpl.drawWidget(CanvasImpl.java:392)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.render(NUIManagerInternal.java:468)
    at org.terasology.engine.modes.StateIngame.renderUserInterface(StateIngame.java:234)
    at org.terasology.engine.modes.StateIngame.render(StateIngame.java:218)
    at org.terasology.engine.subsystem.lwjgl.LwjglGraphics.postUpdate(LwjglGraphics.java:189)
    at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:422)
    at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:368)
    at org.terasology.engine.Terasology.main(Terasology.java:150)

Before that exception was this exception during the explosion:

19:23:23.147 [main] ERROR o.t.e.event.internal.EventSystemImpl - Failed to invoke event
java.lang.NullPointerException: null
    at org.terasology.logic.inventory.ItemCommonSystem.addOrUpdateBlockMeshComponent(ItemCommonSystem.java:102)
    at org.terasology.logic.inventory.ItemCommonSystem.onRenderItemBlockMeshActivated(ItemCommonSystem.java:61)
    at org.terasology.logic.inventory.ItemCommonSystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
    at org.terasology.entitySystem.entity.internal.PojoEntityManager.create(PojoEntityManager.java:167)
    at org.terasology.entitySystem.entity.EntityBuilder.build(EntityBuilder.java:46)
    at org.terasology.world.block.items.BlockItemFactory.newInstance(BlockItemFactory.java:119)
    at org.terasology.world.block.entity.BlockEntitySystem.commonDefaultDropsHandling(BlockEntitySystem.java:129)
    at org.terasology.world.block.entity.BlockEntitySystem.defaultDropsHandling(BlockEntitySystem.java:93)
    at org.terasology.world.block.entity.BlockEntitySystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendConsumableEvent(EventSystemImpl.java:279)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:258)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.world.block.entity.BlockEntitySystem.commonDestroyed(BlockEntitySystem.java:153)
    at org.terasology.world.block.entity.BlockEntitySystem.doDestroy(BlockEntitySystem.java:86)
    at org.terasology.world.block.entity.BlockEntitySystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.logic.health.EntityDestructionAuthoritySystem.onDestroy(EntityDestructionAuthoritySystem.java:31)
    at org.terasology.logic.health.EntityDestructionAuthoritySystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.logic.health.HealthAuthoritySystem.doDamage(HealthAuthoritySystem.java:185)
    at org.terasology.logic.health.HealthAuthoritySystem.checkDamage(HealthAuthoritySystem.java:200)
    at org.terasology.logic.health.HealthAuthoritySystem.onDamage(HealthAuthoritySystem.java:192)
    at org.terasology.logic.health.HealthAuthoritySystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.logic.health.HealthAuthoritySystem.damageEntity(HealthAuthoritySystem.java:125)
    at org.terasology.logic.health.HealthAuthoritySystem.onAttackEntity(HealthAuthoritySystem.java:110)
    at org.terasology.logic.health.HealthAuthoritySystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendConsumableEvent(EventSystemImpl.java:279)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:258)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.logic.characters.CharacterSystem.onAttackRequest(CharacterSystem.java:119)
    at org.terasology.logic.characters.CharacterSystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:269)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:260)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.logic.characters.CharacterSystem.onAttackRequest(CharacterSystem.java:94)
    at org.terasology.logic.characters.CharacterSystemMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:506)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendConsumableEvent(EventSystemImpl.java:279)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:258)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:145)
    at org.terasology.input.internal.BindableButtonImpl.update(BindableButtonImpl.java:214)
    at org.terasology.input.InputSystem.processBindRepeats(InputSystem.java:453)
    at org.terasology.input.InputSystem.update(InputSystem.java:274)
    at org.terasology.engine.modes.StateIngame.handleInput(StateIngame.java:195)
    at org.terasology.engine.subsystem.lwjgl.LwjglInput.postUpdate(LwjglInput.java:54)
    at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:422)
    at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:368)
    at org.terasology.engine.Terasology.main(Terasology.java:150)

Walking through the code i noticed addOrUpdateBlockMeshComponent was updating an Airblock component which does not have a mesh. I believe the player might be attempting to pick up an invisible air block on the ground. I haven't examined the condition after picking up blocks on the ground but i suspect that the null reference exception may be due to an air block. Be aware this is after I set the block to air in a DoDestroyEvent.

pollend commented 8 years ago

this is my workaround at the moment:

  for (Vector3i pos: hasMineBeenMarked) {
            if(!pos.equals(blockComponent.getPosition()))
            worldProvider.setBlock(pos,blockManager.getBlock(BlockManager.AIR_ID));
}

Not sure if this really needs to be addressed. Should the DoDestroyEvent account for the case when the associated block is changed.