Carpet

Carpet

2M Downloads

Running `game_tick()` while server is shutting down throws an error

James103 opened this issue ยท 2 comments

commented

As of Carpet mod 1.4.50 and Minecraft 1.17.1, when the server is shutting down, executing game_tick() will fail with the following error:

Error running game_tick()
java.lang.NullPointerException: Cannot read field "tickDepth" because "carpet.CarpetServer.scriptServer" is null
	at Not Enough Crashes deobfuscated stack trace.(1.17.1+build.37) ~[?:?]
	at carpet.script.api.Auxiliary.lambda$apply$33(Auxiliary.java:687) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$17.lazyEval(Expression.java:597) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.ControlFlow.lambda$apply$9(ControlFlow.java:50) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$15.lazyEval(Expression.java:531) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.ControlFlow.lambda$apply$2(ControlFlow.java:27) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$5.lazyEval(Expression.java:326) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$16(Expression.java:1336) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.ControlFlow.lambda$apply$9(ControlFlow.java:50) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$15.lazyEval(Expression.java:531) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.ControlFlow.lambda$apply$5(ControlFlow.java:33) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$16.lazyEval(Expression.java:567) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.Loops.lambda$apply$25(Loops.java:294) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$14.lazyEval(Expression.java:501) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.Loops.lambda$apply$25(Loops.java:294) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$14.lazyEval(Expression.java:501) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.Loops.lambda$apply$25(Loops.java:294) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$14.lazyEval(Expression.java:501) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.language.ControlFlow.lambda$apply$5(ControlFlow.java:33) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression$16.lazyEval(Expression.java:567) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.lambda$extractOp$19(Expression.java:1344) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.value.FunctionValue.execute(FunctionValue.java:255) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.lambda$call$28(CarpetScriptHost.java:850) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.Expression.evalValue(Expression.java:938) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.call(CarpetScriptHost.java:849) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.lambda$handleCommand$21(CarpetScriptHost.java:713) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.utils.GlocalFlag.whileValueReturn(GlocalFlag.java:42) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.utils.GlocalFlag.getWhileDisabled(GlocalFlag.java:28) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.handleCommand(CarpetScriptHost.java:713) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.execute(CarpetScriptHost.java:165) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at carpet.script.CarpetScriptHost.lambda$addPathToCommand$3(CarpetScriptHost.java:189) ~[fabric-carpet-1.17.1-1.4.50+v211022.jar:?]
	at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:263) ~[brigadier-1.0.18.jar:?]
	at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:177) ~[brigadier-1.0.18.jar:?]
	at net.minecraft.server.command.CommandManager.execute(CommandManager:251) ~[?:?]
	at net.minecraft.server.network.ServerPlayNetworkHandler.executeCommand(ServerPlayNetworkHandler:1222) ~[?:?]
	at net.minecraft.server.network.ServerPlayNetworkHandler.handleMessage(ServerPlayNetworkHandler:1206) ~[?:?]
	at net.minecraft.server.network.ServerPlayNetworkHandler.onGameMessage(ServerPlayNetworkHandler:1189) ~[?:?]
	at net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.apply(ChatMessageC2SPacket:30) ~[?:?]
	at net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket.apply(ChatMessageC2SPacket:7) ~[?:?]
	at net.minecraft.network.NetworkThreadUtils.method_11072(NetworkThreadUtils:21) ~[?:?]
	at net.minecraft.server.ServerTask.run(ServerTask:18) ~[?:?]
	at net.minecraft.util.thread.ThreadExecutor.executeTask(ThreadExecutor:151) ~[?:?]
	at net.minecraft.util.thread.ReentrantThreadExecutor.executeTask(ReentrantThreadExecutor:23) ~[?:?]
	at net.minecraft.server.MinecraftServer.executeTask(MinecraftServer:788) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.server.MinecraftServer.executeTask(MinecraftServer:164) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.util.thread.ThreadExecutor.runTask(ThreadExecutor:125) ~[?:?]
	at net.minecraft.server.MinecraftServer.runOneTask(MinecraftServer:770) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.server.MinecraftServer.runTask(MinecraftServer:764) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.util.thread.ThreadExecutor.runTasks(ThreadExecutor:134) ~[?:?]
	at net.minecraft.server.MinecraftServer.runTasksTillTickEnd(MinecraftServer:749) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.server.MinecraftServer.handler$bnh000$modifiedRunLoop(MinecraftServer:5899) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer:676) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer:270) ~[intermediary-minecraft-1.17.1-client.jar:?]
	at java.lang.Thread.run(Thread.java:831) [?:?]

That would also normally print the following to chat:

Error while evaluating expression: java.lang.NullPointerException: Cannot read field "tickDepth" because "carpet.CarpetServer.scriptServer" is null in system chat at pos 16
loop(10000000, HERE>> game_tick())
Error while evaluating expression

To reproduce:

  1. Run /script run loop(10000000, game_tick())
  2. Pause the game and exit the game before the loop(10000000, game_tick()) completes.
  3. Notice the resulting errors.

Instead of game_tick() throwing a Java exception that gets printed to the Minecraft Log, the function should instead return a Scarpet error saying that the server is shutting down, or just have no effect.

commented

Using the same reproduction steps, the script crashes on the following line of code:

CarpetServer.scriptServer.tickDepth --;

commented

Can reproduce in Carpet mod 1.4.50 and Minecraft 1.17. Updated original comment to reflect newly generated error report.