Demagnetize

Demagnetize

8M Downloads

[CRASH] Null pointer crash

AlienXtream opened this issue ยท 9 comments

commented

Just crafted and placed an advanced demagnetizer and (somehow) it caused a spider to crash the game

-- Entity being ticked --
Entity Type: minecraft:spider (net.minecraft.entity.monster.EntitySpider)

Description: Ticking entity

java.lang.NullPointerException
at link.infra.demagnetize.blocks.DemagnetizerEventHandler.itemSpawned(DemagnetizerEventHandler.java:53)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_628_DemagnetizerEventHandler_itemSpawned_EntityJoinWorldEvent.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraft.world.World.spawnEntity(World.java:1206)
at net.minecraft.world.WorldServer.spawnEntity(WorldServer.java:1058)
at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:1199)
at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:1016)
at net.minecraft.entity.monster.EntityMob.attackEntityFrom(EntityMob.java:70)
at net.minecraft.entity.EntityLivingBase.fall(EntityLivingBase.java:1318)
at net.minecraft.block.Block.onFallenUpon(Block.java:821)
at net.minecraft.entity.Entity.updateFallState(Entity.java:1132)
at net.minecraft.entity.EntityLivingBase.updateFallState(EntityLivingBase.java:215)
at net.minecraft.entity.Entity.move(Entity.java:896)
at net.minecraft.entity.EntityLivingBase.travel(EntityLivingBase.java:1951)
at net.minecraft.entity.EntityLivingBase.onLivingUpdate(EntityLivingBase.java:2386)
at net.minecraft.entity.EntityLiving.onLivingUpdate(EntityLiving.java:678)
at net.minecraft.entity.monster.EntityMob.onLivingUpdate(EntityMob.java:45)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:2172)
at net.minecraft.entity.EntityLiving.onUpdate(EntityLiving.java:377)
at net.minecraft.entity.monster.EntityMob.onUpdate(EntityMob.java:50)
at net.minecraft.entity.monster.EntitySpider.onUpdate(SourceFile:87)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:1993)
at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:832)
at net.minecraft.world.World.updateEntity(World.java:1955)
at net.minecraft.world.World.redirect$updateEntity$zcg000(World.java:5117)
at net.minecraft.world.World.updateEntities(World.java:1759)
at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:613)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:767)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:668)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:252)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)
at java.lang.Thread.run(Thread.java:745)

A detailed walkthrough of the error, its code path and all known details is as follows:

-- Entity being ticked --
Entity Type: minecraft:spider (net.minecraft.entity.monster.EntitySpider)
Entity ID: 62903
Entity Name: Spider
Entity's Exact location: -617.30, 95.63, 352.17
Entity's Block location: World: (-618,95,352), Chunk: (at 6,5,0 in -39,22; contains blocks -624,0,352 to -609,255,367), Region: (-2,0; contains chunks -64,0 to -33,31, blocks -1024,0,0 to -513,255,511)
Entity's Momentum: -8.15, -1.55, 0.03
Entity's Passengers: []
Entity's Vehicle: ERROR NullPointerException: null
Entity NBT: {HurtByTimestamp:0,ForgeData:{Hats_hatInfo:"",CursedEarth:57,excompressum:{NoCompress:1b}},Attributes:[{Base:-2.0d,Modifiers:[{UUIDMost:2189974539282499591L,UUIDLeast:-6477178668949725305L,Amount:1.0d,Operation:0,Name:"normal"}],Name:"tc.mobmod"},{Base:0.0d,Name:"tc.mobmodtaint"},{Base:16.0d,Name:"generic.maxHealth"},{Base:0.0d,Name:"generic.knockbackResistance"},{Base:0.30000001192092896d,Modifiers:[{UUIDMost:-1928099995943284879L,UUIDLeast:-7424676046943233794L,Amount:1.2d,Operation:1,Name:"CursedEarth"}],Name:"generic.movementSpeed"},{Base:0.0d,Name:"generic.armor"},{Base:0.0d,Name:"generic.armorToughness"},{Base:1.0d,Name:"forge.swimSpeed"},{Base:16.0d,Modifiers:[{UUIDMost:6451205988273767315L,UUIDLeast:-9199561264936245099L,Amount:-0.03173931209583872d,Operation:1,Name:"Random spawn bonus"}],Name:"generic.followRange"},{Base:2.0d,Modifiers:[{UUIDMost:-1928099995943284879L,UUIDLeast:-7424676046943233794L,Amount:1.5d,Operation:1,Name:"CursedEarth"}],Name:"generic.attackDamage"}],Invulnerable:0b,FallFlying:0b,PortalCooldown:0,AbsorptionAmount:0.0f,FallDistance:20.680437f,DeathTime:0s,ForgeCaps:{"nuclearcraft:capability_entity_rads":{radiationResistance:0.0d,totalRads:0.0d,radiationLevel:0.0d,radXCooldown:0.0d,radXWoreOff:0b,radawayCooldown:0.0d},"tinkertoolleveling:entityxp":[],"dsurround:emojidata":{as:1,es:0,et:0},"thebetweenlands:entity_gems":{gems:[]},"thebetweenlands:custom_step_sound":{},"llibrary:extendedentitydatacapability":{},"thebetweenlands:puppet":{ticks:0},"twilightforest:cap_shield":{permshields:0,tempshields:0},"everlastingabilities:org.cyclops.everlastingabilities.api.capability.imutableabilitystore":[],"thebetweenlands:equipment":{amuletSlots:1}},HandDropChances:[0.085f,0.085f],PersistenceRequired:0b,Motion:[-8.151707947919403d,-1.551131103621314d,0.025650084714350672d],Leashed:0b,UUIDLeast:-5634626572217315992L,Health:0.0f,LeftHanded:0b,Air:300s,OnGround:1b,Dimension:0,Rotation:[323.70844f,0.0f],UpdateBlocked:0b,HandItems:[{},{}],ArmorDropChances:[0.085f,0.085f,0.085f,0.085f],UUIDMost:-6018120370437535186L,Pos:[-617.3000000119209d,95.625d,352.165054201575d],Fire:-1s,ArmorItems:[{},{},{},{}],CanPickUpLoot:0b,HurtTime:10s}

commented

Was this in singleplayer or multiplayer (dedicated server)?

commented

singleplayer

commented

my game IS heavily modded (~380 mods) so its likely to be a mod conflict. i can (temporarily) disable your mod and send some screenshots of the setup if that would help though its just a mob grinder

commented

I think I know what caused it, and it'll happen regardless of other mods or the way in which you use it. I should be able to push a fix today.

commented

This should be fixed in commit 74711c7, and is on CurseForge now as version 1.0.1.

commented

that actually makes sense as i had a "random things" collector picking up the drops and with that many mods tick rate can dip so there was something removing items from the word and a slight discrepancy between "server" and client.

i take it you are now clearing an entry on the array list if it returns null?

commented

The existing code gets a reference to each tile entity (which every demagnetizer has) and clears it if it is null or isInvalid() is true, but I did not account for the possibility that the reference itself could be null.
Additionally, ArrayLists in Java are not thread safe, so when accessed from multiple threads even the underlying data backing the list could be read incorrectly and break my code.

The fix is to:

  1. Check if the reference itself is not null
  2. Synchronize (using the java synchronized keyword) accesses to the ArrayList so that multiple threads cannot modify/read it at once, so there cannot be any data corruption.

A side note: the list itself is not of items, so another mod removing items would not affect my code. The error occurred when the spider spawned an item. The list is actually of Demagnetizer Tile Entities, so if you unloaded/loaded chunks with demagnetizers or placed/removed a demagnetizer they could desync.

commented

mind sharing what the issue was? its little quirks like this i find facinaiting :)

commented

I'm not exactly sure what happened in your example, but I had an ArrayList that was being accessed from both the server (integrated server for singleplayer) and client threads at once. This apparently caused one of the elements to become null (maybe it was removed while another thread was looping through the list) so the .get() function didn't work.

The crash log talks about a spider, as the crash happened when the items dropped by the spider's death were processed by my mod.