New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating Turtle NPCs occasionally cause NPE while ticking entity #1569

Open
SnoFox opened this Issue Sep 22, 2018 · 7 comments

Comments

Projects
None yet
3 participants
@SnoFox

SnoFox commented Sep 22, 2018

The output of command /version on my server is: git-Spigot-38536ab-8164f4b (MC: 1.13.1) (Implementing API version 1.13.1-R0.1-SNAPSHOT)
The output of command /version citizens on my server is: 2.0.24-SNAPSHOT (build 1570)

Reproduction steps:
I spawned a baby Turtle NPC with my plugin using code similar to:

NPC npc = npcRegistry.createNPC(EntityType.OCELOT, "No name");
npc.setBukkitEntityType(npcSpec.getEntityType());
npc.setProtected(true);
npc.setName(npcSpec.getName());
MetadataStore meta = npc.data();
meta.setPersistent(NPC.COLLIDABLE_METADATA, false);
meta.setPersistent(NPC.SILENT_METADATA, true);

Once I'm in water, I also call npc.setFlyable(true)

I had the turtle follow me by calling NPC.getNavigator().setTarget(Location) on every PlayerMoveEvent where I was the source.

After swimming around in an ocean biome for a few minutes, the crashbug is triggered. I can offer the world and more information on my plugin if this is insufficient information to reproduce the crash.

Server logs: https://gist.github.com/SnoFox/fdc4bb0673f1b0dc2412bb0c77f4fd35

Crash log
---- Minecraft Crash Report ----
// Ouch. That hurt :(

Time: 9/21/18, 1:13 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
	at net.minecraft.server.v1_13_R2.NavigationAbstract.t(SourceFile:360)
	at net.minecraft.server.v1_13_R2.EntityInsentient.c(EntityInsentient.java:1288)
	at net.minecraft.server.v1_13_R2.EntityLiving.k(EntityLiving.java:2265)
	at net.minecraft.server.v1_13_R2.EntityInsentient.k(EntityInsentient.java:509)
	at net.minecraft.server.v1_13_R2.EntityAgeable.k(EntityAgeable.java:145)
	at net.minecraft.server.v1_13_R2.EntityAnimal.k(EntityAnimal.java:27)
	at net.minecraft.server.v1_13_R2.EntityTurtle.k(EntityTurtle.java:221)
	at net.minecraft.server.v1_13_R2.EntityLiving.tick(EntityLiving.java:2100)
	at net.minecraft.server.v1_13_R2.EntityInsentient.tick(EntityInsentient.java:247)
	at net.minecraft.server.v1_13_R2.World.entityJoinedWorld(World.java:1380)
	at net.minecraft.server.v1_13_R2.World.g(World.java:1347)
	at net.minecraft.server.v1_13_R2.World.tickEntities(World.java:1181)
	at net.minecraft.server.v1_13_R2.WorldServer.tickEntities(WorldServer.java:601)
	at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:972)
	at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417)
	at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:835)
	at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:733)
	at java.base/java.lang.Thread.run(Thread.java:844)


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

-- Head --
Thread: Server thread
Stacktrace:
	at net.minecraft.server.v1_13_R2.NavigationAbstract.t(SourceFile:360)
	at net.minecraft.server.v1_13_R2.EntityInsentient.c(EntityInsentient.java:1288)
	at net.minecraft.server.v1_13_R2.EntityLiving.k(EntityLiving.java:2265)
	at net.minecraft.server.v1_13_R2.EntityInsentient.k(EntityInsentient.java:509)
	at net.minecraft.server.v1_13_R2.EntityAgeable.k(EntityAgeable.java:145)
	at net.minecraft.server.v1_13_R2.EntityAnimal.k(EntityAnimal.java:27)
	at net.minecraft.server.v1_13_R2.EntityTurtle.k(EntityTurtle.java:221)
	at net.minecraft.server.v1_13_R2.EntityLiving.tick(EntityLiving.java:2100)
	at net.minecraft.server.v1_13_R2.EntityInsentient.tick(EntityInsentient.java:247)
	at net.minecraft.server.v1_13_R2.World.entityJoinedWorld(World.java:1380)
	at net.minecraft.server.v1_13_R2.World.g(World.java:1347)

-- Entity being ticked --
Details:
	Entity Type: minecraft:turtle (net.citizensnpcs.nms.v1_13_R2.entity.TurtleController.EntityTurtleNPC)
	Entity ID: 485
	Entity Name: Dude
	Entity's Exact location: 114.81, 50.02, 55.63
	Entity's Block location: World: (114,50,55), Chunk: (at 2,3,7 in 7,3; contains blocks 112,0,48 to 127,255,63), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Entity's Momentum: -0.16, 0.02, 0.08
	Entity's Passengers: []
	Entity's Vehicle: ~~ERROR~~ NullPointerException: null
Stacktrace:
	at net.minecraft.server.v1_13_R2.World.tickEntities(World.java:1181)
	at net.minecraft.server.v1_13_R2.WorldServer.tickEntities(WorldServer.java:601)

-- Affected level --
Details:
	Level name: world
	All players: 1 total; [EntityPlayer['SnoFox'/224, l='world', x=110.10, y=51.39, z=57.00](SnoFox at 110.10463443767154,51.394573372758984,57.00280765970838)]
	Chunk stats: ServerChunkCache: 569 Drop: 0
	Level seed: -6392693364514661142
	Level generator: ID 00 - default, ver 1. Features enabled: true
	Level generator options: {}
	Level spawn location: World: (64,70,224), Chunk: (at 0,4,0 in 4,14; contains blocks 64,0,224 to 79,255,239), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
	Level time: 3700371 game time, 1144 day time
	Level dimension: 0
	Level storage version: 0x04ABD - Anvil
	Level weather: Rain time: 1 (now: false), thunder time: 1 (now: false)
	Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
Stacktrace:
	at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:972)
	at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417)
	at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:835)
	at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:733)
	at java.base/java.lang.Thread.run(Thread.java:844)

-- System Details --
Details:
	Minecraft Version: 1.13.1
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 9.0.4, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 473087488 bytes (451 MB) / 1470103552 bytes (1402 MB) up to 4284481536 bytes (4086 MB)
	JVM Flags: 0 total; 
	CraftBukkit Information: 
   Running: CraftBukkit version git-Spigot-38536ab-8164f4b (MC: 1.13.1) (Implementing API version 1.13.1-R0.1-SNAPSHOT) true
   Plugins: { SnoLib v1.0.0 net.snofox.minecraft.snolib.SnoLib [SnoFox], Citizens v2.0.24-SNAPSHOT (build 1570) net.citizensnpcs.Citizens [aPunch, fullwall], PallyPets v1.0.0 net.snofox.minecraft.pallypets.PallyPets [SnoFox],}
   Warnings: DEFAULT
   Reload Count: 0
   Threads: { TIMED_WAITING Server Infinisleeper: [java.base@9.0.4/java.lang.Thread.sleep(Native Method), app//net.minecraft.server.v1_13_R2.DedicatedServer$1.run(DedicatedServer.java:66)], WAITING Finalizer: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151), java.base@9.0.4/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:172), java.base@9.0.4/java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)], TIMED_WAITING Common-Cleaner: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151), java.base@9.0.4/jdk.internal.ref.CleanerImpl.run(CleanerImpl.java:148), java.base@9.0.4/java.lang.Thread.run(Thread.java:844), java.base@9.0.4/jdk.internal.misc.InnocuousThread.run(InnocuousThread.java:122)], WAITING Thread-2: [java.base@9.0.4/jdk.internal.misc.Unsafe.park(Native Method), java.base@9.0.4/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194), java.base@9.0.4/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2062), java.base@9.0.4/java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:435), app//com.mojang.util.QueueLogAppender.getNextLogEvent(QueueLogAppender.java:77), app//org.bukkit.craftbukkit.v1_13_R2.util.TerminalConsoleWriterThread.run(TerminalConsoleWriterThread.java:27), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)], WAITING Snooper Timer: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.lang.Object.wait(Object.java:516), java.base@9.0.4/java.util.TimerThread.mainLoop(Timer.java:527), java.base@9.0.4/java.util.TimerThread.run(Timer.java:506)], TIMED_WAITING Spigot Watchdog Thread: [java.base@9.0.4/java.lang.Thread.sleep(Native Method), app//org.spigotmc.WatchdogThread.run(WatchdogThread.java:92)], TIMED_WAITING Timer-0: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.util.TimerThread.mainLoop(Timer.java:553), java.base@9.0.4/java.util.TimerThread.run(Timer.java:506)], TIMED_WAITING Spigot Metrics Thread: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.util.TimerThread.mainLoop(Timer.java:553), java.base@9.0.4/java.util.TimerThread.run(Timer.java:506)], RUNNABLE Server thread: [java.base@9.0.4/java.lang.Thread.dumpThreads(Native Method), java.base@9.0.4/java.lang.Thread.getAllStackTraces(Thread.java:1705), app//org.bukkit.craftbukkit.v1_13_R2.CraftCrashReport.call(CraftCrashReport.java:32), app//net.minecraft.server.v1_13_R2.CrashReportSystemDetails.a(SourceFile:79), app//net.minecraft.server.v1_13_R2.CrashReport.h(CrashReport.java:66), app//net.minecraft.server.v1_13_R2.CrashReport.<init>(CrashReport.java:34), app//net.minecraft.server.v1_13_R2.CrashReport.a(CrashReport.java:260), app//net.minecraft.server.v1_13_R2.World.tickEntities(World.java:1184), app//net.minecraft.server.v1_13_R2.WorldServer.tickEntities(WorldServer.java:601), app//net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:972), app//net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417), app//net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:835), app//net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:733), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)], TIMED_WAITING ObjectCleanerThread: [java.base@9.0.4/java.lang.Object.wait(Native Method), java.base@9.0.4/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151), app//io.netty.util.internal.ObjectCleaner$1.run(ObjectCleaner.java:54), app//io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)], RUNNABLE DestroyJavaVM: [], RUNNABLE Reference Handler: [java.base@9.0.4/java.lang.ref.Reference.waitForReferencePendingList(Native Method), java.base@9.0.4/java.lang.ref.Reference.processPendingReferences(Reference.java:174), java.base@9.0.4/java.lang.ref.Reference.access$000(Reference.java:44), java.base@9.0.4/java.lang.ref.Reference$ReferenceHandler.run(Reference.java:138)], RUNNABLE Server console handler: [java.base@9.0.4/java.io.FileInputStream.readBytes(Native Method), java.base@9.0.4/java.io.FileInputStream.read(FileInputStream.java:256), java.base@9.0.4/java.io.BufferedInputStream.fill(BufferedInputStream.java:246), java.base@9.0.4/java.io.BufferedInputStream.read(BufferedInputStream.java:265), app//org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read(NonBlockingInputStream.java:248), app//org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:261), app//org.bukkit.craftbukkit.libs.jline.internal.InputStreamReader.read(InputStreamReader.java:198), app//org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readCharacter(ConsoleReader.java:2145), app//org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLineSimple(ConsoleReader.java:3183), app//org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:2333), app//org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:2269), app//org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.readLine(ConsoleReader.java:2257), app//net.minecraft.server.v1_13_R2.DedicatedServer$2.run(DedicatedServer.java:93)], RUNNABLE Attach Listener: [], RUNNABLE Signal Dispatcher: [], RUNNABLE Netty Server IO #1: [java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159), java.base@9.0.4/sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86), java.base@9.0.4/sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97), app//io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:756), app//io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:411), app//io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)], RUNNABLE Netty Server IO #0: [java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:296), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:278), java.base@9.0.4/sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:159), java.base@9.0.4/sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:86), java.base@9.0.4/sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97), app//io.netty.channel.nio.NioEventLoop.select(NioEventLoop.java:756), app//io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:411), app//io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)], TIMED_WAITING File IO Thread: [java.base@9.0.4/java.lang.Thread.sleep(Native Method), app//net.minecraft.server.v1_13_R2.FileIOThread.c(SourceFile:59), app//net.minecraft.server.v1_13_R2.FileIOThread.run(SourceFile:35), java.base@9.0.4/java.lang.Thread.run(Thread.java:844)],}
   Recent tasks from 3164-3194{}
	Profiler Position: N/A (disabled)
	Player Count: 1 / 20; [EntityPlayer['SnoFox'/224, l='world', x=110.10, y=51.39, z=57.00](SnoFox at 110.10463443767154,51.394573372758984,57.00280765970838)]
	Data Packs: vanilla, file/bukkit (incompatible)
	Is Modded: Definitely; Server brand changed to 'Spigot'
	Type: Dedicated Server (map_server.txt)
@mcmonkey4eva

This comment has been minimized.

Show comment
Hide comment
@mcmonkey4eva

mcmonkey4eva Sep 22, 2018

Member

Could you please upload any relevant log info as text to pastebin, not as a .tar.gz file on a generic file server.

I had the turtle follow me by calling NPC.getNavigator().setTarget(Location) on every PlayerMoveEvent where I was the source.
^ That's a dangerous way of doing that - PlayerMoveEvent fires extremely rapidly (often every tick!).
The navigator should generally not be updated more than once every second or so.
There's also a very helpful setTarget(Entity ...) method to use instead of the Location one, which will automatically handle keeping the NPC moving towards your player, rather than having to constantly send in new Location values.

Member

mcmonkey4eva commented Sep 22, 2018

Could you please upload any relevant log info as text to pastebin, not as a .tar.gz file on a generic file server.

I had the turtle follow me by calling NPC.getNavigator().setTarget(Location) on every PlayerMoveEvent where I was the source.
^ That's a dangerous way of doing that - PlayerMoveEvent fires extremely rapidly (often every tick!).
The navigator should generally not be updated more than once every second or so.
There's also a very helpful setTarget(Entity ...) method to use instead of the Location one, which will automatically handle keeping the NPC moving towards your player, rather than having to constantly send in new Location values.

@fullwall

This comment has been minimized.

Show comment
Hide comment
@fullwall

fullwall Sep 22, 2018

Member

This NPE seems to be a minecraft bug but I would second @mcmonkey4eva that you shouldn't set target too often.

Member

fullwall commented Sep 22, 2018

This NPE seems to be a minecraft bug but I would second @mcmonkey4eva that you shouldn't set target too often.

@SnoFox

This comment has been minimized.

Show comment
Hide comment
@SnoFox

SnoFox Sep 22, 2018

@mcmonkey4eva - updated the original bug report to include a gist to the relevant logs.

As for the input on how I'm using setTarget(): Completely understandable. I do plan on having the target update less often; I will, at some point, have a system to cause target updates less often. Iterating on a new plugin and all.

That said, I did see the setTarget(Entity) method, however I am trying to have NPCs at a specific location relative to the Player, which is why I have it set up like this for development.

SnoFox commented Sep 22, 2018

@mcmonkey4eva - updated the original bug report to include a gist to the relevant logs.

As for the input on how I'm using setTarget(): Completely understandable. I do plan on having the target update less often; I will, at some point, have a system to cause target updates less often. Iterating on a new plugin and all.

That said, I did see the setTarget(Entity) method, however I am trying to have NPCs at a specific location relative to the Player, which is why I have it set up like this for development.

@mcmonkey4eva

This comment has been minimized.

Show comment
Hide comment
@mcmonkey4eva

mcmonkey4eva Sep 22, 2018

Member

Appears to be an error (NPE) on https://github.com/CitizensDev/Citizens2/blob/master/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java#L291 in that log
getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false));

Member

mcmonkey4eva commented Sep 22, 2018

Appears to be an error (NPE) on https://github.com/CitizensDev/Citizens2/blob/master/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java#L291 in that log
getEntity().setGlowing(data().get(NPC.GLOWING_METADATA, false));

@SnoFox

This comment has been minimized.

Show comment
Hide comment
@SnoFox

SnoFox Sep 22, 2018

Do you think that's related to the crashbug? I've been getting that NPE every time my plugin attempts to teleport any NPC; while I haven't had a chance to investigate that yet, it has continued working as designed... Sans the turtle, I s'pose.

SnoFox commented Sep 22, 2018

Do you think that's related to the crashbug? I've been getting that NPE every time my plugin attempts to teleport any NPC; while I haven't had a chance to investigate that yet, it has continued working as designed... Sans the turtle, I s'pose.

@fullwall

This comment has been minimized.

Show comment
Hide comment
@fullwall

fullwall Sep 24, 2018

Member

@mcmonkey4eva hmm I feel like it should be spawned there, data() never returns null

Member

fullwall commented Sep 24, 2018

@mcmonkey4eva hmm I feel like it should be spawned there, data() never returns null

@mcmonkey4eva

This comment has been minimized.

Show comment
Hide comment
@mcmonkey4eva

mcmonkey4eva Oct 12, 2018

Member

Sorry for slow handling here, @SnoFox
Does this occur on latest Citizens dev builds (via http://ci.citizensnpcs.co/job/Citizens2/ )? If so, could you post an updated copy of relevant error messages (just in case they've changed)

Member

mcmonkey4eva commented Oct 12, 2018

Sorry for slow handling here, @SnoFox
Does this occur on latest Citizens dev builds (via http://ci.citizensnpcs.co/job/Citizens2/ )? If so, could you post an updated copy of relevant error messages (just in case they've changed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment