From 5bf7d3cb4bbb090c815ef3ca82810f6277631b81 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 22 Sep 2013 16:56:24 +0100 Subject: [PATCH] Fix NPE when loading second single-player world After leaving a single-player world, getServer() can return null, resulting in the stack trace below, "Fatal errors were detected during the transition from SERVER_STOPPING to SERVER_ABOUT_TO_START", "The ForgeModLoader state engine has become corrupted" and the client getting stuck forever. Exception in thread "Server thread" java.lang.NullPointerException at cpw.mods.fml.client.FMLClientHandler.serverStopped(FMLClientHandler.java:620) at cpw.mods.fml.common.FMLCommonHandler.handleServerStopped(FMLCommonHandler.java:468) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:471) at net.minecraft.server.ThreadMinecraftServer.run(SourceFile:583) --- fml/client/cpw/mods/fml/client/FMLClientHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index 77773e923..c42743c90 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -617,9 +617,11 @@ public class FMLClientHandler implements IFMLSidedHandler public void serverStopped() { // If the server crashes during startup, it might hang the client- reset the client so it can abend properly. - if (!getServer().func_71200_ad()) + MinecraftServer server = getServer(); + + if (server != null && !server.func_71200_ad()) { - ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, getServer(), true, "field_71296"+"_Q","serverIs"+"Running"); + ObfuscationReflectionHelper.setPrivateValue(MinecraftServer.class, server, true, "field_71296"+"_Q","serverIs"+"Running"); } } }