-
Bug
-
Resolution: Fixed
-
Minecraft 1.11.2, Minecraft 1.12.2, Minecraft 1.13-pre5
-
Confirmed
The bug
When you start to connect to a server but it fails to connect for whatever reason, there is a chance that Minecraft might crash.
Code analysis
Based on 1.11 decompiled using MCP 9.35 rc1
The method net.minecraft.client.multiplayer.GuiConnecting.connect(String, int) creates a new thread to connect to a server. When the connection is closed a new net.minecraft.client.gui.GuiDisconnected is shown. The problem is that this class does not have a constructor and therefor the mc field storing the reference to the Minecraft instance remains null. This GUI is then displayed using the method net.minecraft.client.Minecraft.displayGuiScreen(GuiScreen) which would call the method net.minecraft.client.gui.GuiScreen.setWorldAndResolution(Minecraft, int, int) and set a value for the field. The problem here is that as this happens in a seperate thread the main thread might try to render this GUI already while the mc field is still null. This causes this crash then.
pokechu22 suggests in general to not directly call the Minecraft.displayGuiScreen(GuiScreen) method from other threads but instead create a Callable for it then call the method Minecraft.addScheduledTask(Callable<V> callableToSchedule) with it as argument.
How to reproduce (modded version)
Note: This can be reproduced with an unmodded version of Minecraft but there it will not always happen, whereas with this modification it should be always reproducible.
You can change the method net.minecraft.client.Minecraft.displayGuiScreen(GuiScreen) to sleep for some seconds before the method net.minecraft.client.gui.GuiScreen.setWorldAndResolution(Minecraft, int, int) of the GUI is called when this GUI is an instance of GuiDisconnected. Then Minecraft should crash if you try to connect to a server with a non-existant host or to an offline server.
To reproduce (jdb)
Similarly, adding a breakpoint in displayGuiScreen after assigning the field but before setWorldAndResolution can be used to trigger this same issue. As of 1.13-pre5, this is cep:712, so attaching jdb to a running minecraft and then entering stop at ceg:712 will let you reproduce this issue. Note that you will need to resume each time a new GUI has opened, so it may make sense to set the breakpoint only after entering the multiplayer screen. Once the breakpoint has been hit in a "Server Connector" thread, wait a few seconds and then enter resume one more time and the game will crash. (You may have to enter resume one more time).
Stacktrace
To make sure this report can be found when searching for the stacktrace
Description: Rendering screen java.lang.NullPointerException: Rendering screen at bho.d_(SourceFile:437) at bho.c(SourceFile:433) at bhc.a(SourceFile:44) at bqe.a(SourceFile:1078) at bes.av(SourceFile:993) at bes.a(SourceFile:398) at net.minecraft.client.main.Main.main(SourceFile:124)