Crash on Client Tick - GTNetwork.sendToServer() causes NPE before connection established
KowaretaTerra opened this issue · 9 comments
Checked for existing issues
- I have checked for existing issues, and have found none.
Tested latest version
- I have checked that this occurs on the latest version.
GregTech CEu Version
7.1.4
Minecraft Version
1.20.1 Forge
Recipe Viewer Installed
JEI
Environment
Multiplayer - Dedicated Server
Cross-Mod Interaction
Yes
Other Installed Mods
TerraFirmaGreg - Modern
Expected Behavior
Connection to the server and packets being sent after connection is established.
Actual Behavior
The game crashes on client tick due to GTNetwork.sendToServer() being called when the Minecraft client hasn't fully initialized (likely before the ClientPacketListener is ready).
This causes a NullPointerException in:
GTNetwork.sendToServer()
The crash seems to originate from SyncedKeyMapping.onClientTick() — likely triggered either:
Just before or during server connection
Or right after disconnecting
Or during some automatic key-binding / client event logic
The Crash log:
java.lang.NullPointerException: Cannot invoke "net.minecraft.client.multiplayer.ClientPacketListener.m_104910_()"
because the return value of "net.minecraft.client.Minecraft.m_91403_()" is null
at net.minecraftforge.network.simple.SimpleChannel.sendToServer(SimpleChannel.java:87)
at com.gregtechceu.gtceu.common.network.GTNetwork.sendToServer(GTNetwork.java:37)
at com.gregtechceu.gtceu.utils.input.SyncedKeyMapping.onClientTick(SyncedKeyMapping.java:228)
Steps to Reproduce
-
Join modded server with GTCEu installed
-
Let the client load in (or press a GTCEu keybind early)
-
Crash happens consistently depending on timing
Additional Information
Suggested Fix
Add a null check for Minecraft.getInstance().getConnection() before sending packets from the client:
if (Minecraft.getInstance().getConnection() != null) {
// send packet
}
might be dupe of #3825
Can't reproduce locally (even if I introduce network delay/drops via iptables)
Similar crash on TerraFirmaGreg
When connecting to the server crashes after 5-10 minutes of play with the following error
could you collect server-side logs when it happens?
This the log from when I begin to join the server:
[17Sep2025 16:48:05.987] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Kowareta joined the game [17Sep2025 16:48:06.298] [Server thread/INFO] [fallingtrees | Config/]: Sending common config 'fallingtrees:fallingtrees_common' to Kowareta [17Sep2025 16:48:06.344] [Server thread/INFO] [APTweaks(Player)/]: Player Kowareta ServerPlayer['Kowareta'/1, l='ServerLevel[world]', x=-3724.98, y=77.00, z=-3491.10] logged in and will be protected for 90 secs. [17Sep2025 16:48:06.359] [Server thread/INFO] [Jade/]: Syncing config to Kowareta (2a5ebade-662f-44d6-8094-13b8fd4f0522) [17Sep2025 16:48:06.366] [Server thread/INFO] [net.dries007.tfc.util.calendar.CalendarEventHandler/]: Player Logged In - Checking for Calendar Updates. [17Sep2025 16:48:06.366] [Server thread/INFO] [net.dries007.tfc.util.calendar.Calendar/]: Calendar = true, Daylight = true due to players logged in [17Sep2025 16:48:11.109] [Server thread/ERROR] [net.minecraftforge.fml.loading.RuntimeDistCleaner/DISTXFORM]: Attempted to load class com/mojang/blaze3d/vertex/PoseStack for invalid dist DEDICATED_SERVER [17Sep2025 16:48:11.109] [Server thread/WARN] [Radium Class Analysis/]: Radium Class Analysis Error: Class net.dries007.tfc.common.blocks.devices.QuernBlock cannot be analysed, because getting declared methods crashes with RuntimeException: Attempted to load class com/mojang/blaze3d/vertex/PoseStack for invalid dist DEDICATED_SERVER. This is usually caused by modded entities declaring methods that have a return type or parameter type that is annotated with @onlyin(Dist.CLIENT). Loading the type is not possible, because it only exists in the CLIENT environment. The recommended fix is to annotate the method with this argument or return type with the same annotation. Lithium handles this error by assuming the class cannot be included in some optimizations. [17Sep2025 16:48:11.176] [Server thread/INFO] [APTweaks(Core)/]: [APTweaks:Core] ? Level load for minecraft:overworld changed from VERY_LOW (avg. 1.002792) to LOW (avg. 18.090614) [17Sep2025 16:48:11.394] [Server thread/ERROR] [net.minecraftforge.fml.loading.RuntimeDistCleaner/DISTXFORM]: Attempted to load class com/mojang/blaze3d/vertex/PoseStack for invalid dist DEDICATED_SERVER [17Sep2025 16:48:11.395] [Server thread/WARN] [Radium Class Analysis/]: Radium Class Analysis Error: Class com.eerussianguy.firmalife.common.blocks.greenhouse.QuadPlanterBlock cannot be analysed, because getting declared methods crashes with RuntimeException: Attempted to load class com/mojang/blaze3d/vertex/PoseStack for invalid dist DEDICATED_SERVER. This is usually caused by modded entities declaring methods that have a return type or parameter type that is annotated with @onlyin(Dist.CLIENT). Loading the type is not possible, because it only exists in the CLIENT environment. The recommended fix is to annotate the method with this argument or return type with the same annotation. Lithium handles this error by assuming the class cannot be included in some optimizations. [17Sep2025 16:48:18.282] [Netty Server IO #1/INFO] [fallingtrees | Config/]: Received client config 'fallingtrees:fallingtrees_client' from Kowareta [17Sep2025 16:48:52.325] [Server thread/INFO] [net.minecraft.server.network.ServerGamePacketListenerImpl/]: Kowareta lost connection: Timed out [17Sep2025 16:48:52.326] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: Kowareta left the game [17Sep2025 16:48:52.332] [Server thread/INFO] [net.dries007.tfc.util.calendar.CalendarEventHandler/]: Player Logged Out - Checking for Calendar Updates. [17Sep2025 16:48:52.332] [Server thread/INFO] [net.dries007.tfc.util.calendar.Calendar/]: Calendar = false, Daylight = false (true) due to no players logged in. What's wrong
I go through the same problem. Game crashes randomly from time to time. My server runs on physical dedicated server that connected to my PC via 2.5Gb network segment. My ping is shown as 0ms witch means it less then 1 ms. And it still happens from time to time. It isn't by any means network problem.
Can we just accept the possibility that variable (or whatever it is) is able to have a null as a value and just handle it?
It is not a big deal from my perspective. We can just skip execution and log that this situation happened once more.
And can even expand logs to find out the reason.
Right now it's annoying to restart the game from time to time. And the problem is still taking place. Solving it is more important then spending some unknown amount of time to find out the reason.
Also on TerraFirmaGreg - Modern: We're also having crashes, and we're sure the issue is quite similar. We see a crash to desktop every 5-30 minutes.
Server side logs only state time out. This was one of the many crashes he's had; you can see that, from the time stamps, from time joined to time of disconnect, that he was only online for about 3 minutes.
[16Oct2025 21:16:12.440] [Server thread/INFO] [net.minecraft.server.players.PlayerList/]: [PLAYER NAME][/(IP)] logged in with entity id 3809823 at (6747.434883634037, 71.0, 6152.063074425594)
[16Oct2025 21:16:12.621] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: [PLAYER NAME] joined the game
[16Oct2025 21:16:12.701] [Server thread/INFO] [fallingtrees | Config/]: Sending common config 'fallingtrees:fallingtrees_common' to [PLAYER NAME]
[16Oct2025 21:16:12.717] [Server thread/INFO] [net.dries007.tfc.util.calendar.CalendarEventHandler/]: Player Logged In - Checking for Calendar Updates.
[16Oct2025 21:16:12.718] [Server thread/INFO] [net.dries007.tfc.util.calendar.Calendar/]: Calendar = true, Daylight = true due to players logged in
[16Oct2025 21:16:12.719] [Server thread/INFO] [APTweaks(Player)/]: Player [PLAYER NAME] ServerPlayer['[PLAYER NAME]'/3809823, l='ServerLevel[world]', x=6747.43, y=71.00, z=6152.06] logged in and will be protected for 90 secs.
[16Oct2025 21:16:12.719] [Server thread/INFO] [Jade/]: Syncing config to [PLAYER NAME] (758e2484-1b3c-4eca-bb90-37c272da19fa)
[16Oct2025 21:16:26.306] [Netty Server IO #11/INFO] [fallingtrees | Config/]: Received client config 'fallingtrees:fallingtrees_client' from [PLAYER NAME]
[16Oct2025 21:16:57.508] [Server thread/INFO] [do_a_barrel_roll/]: Client of [PLAYER NAME] accepted server config.
[16Oct2025 21:17:05.240] [Server thread/INFO] [APTweaks(Player)/]: Protected Player [PLAYER NAME] was successful validated after 52 secs.
[16Oct2025 21:17:05.241] [Server thread/INFO] [APTweaks(Player)/]: Removing player protection invulnerable from player [PLAYER NAME]!
[16Oct2025 21:17:37.242] [Server thread/INFO] [APTweaks(Core)/]: [APTweaks:Core] ↑ Server load changed from VERY_LOW (avg. 18.801937103271484) to LOW (avg. 21.007444381713867)
[16Oct2025 21:17:52.241] [Server thread/INFO] [APTweaks(Core)/]: [APTweaks:Core] ↓ Server load changed from LOW (avg. 21.007444381713867) to VERY_LOW (avg. 14.843698501586914)
[16Oct2025 21:19:12.751] [Server thread/INFO] [net.minecraft.server.network.ServerGamePacketListenerImpl/]: [PLAYER NAME] lost connection: Timed out
[16Oct2025 21:19:12.752] [Server thread/INFO] [net.minecraft.server.MinecraftServer/]: [PLAYER NAME] left the game
[16Oct2025 21:19:12.754] [Server thread/INFO] [net.dries007.tfc.util.calendar.CalendarEventHandler/]: Player Logged Out - Checking for Calendar Updates.
[16Oct2025 21:19:12.754] [Server thread/INFO] [net.dries007.tfc.util.calendar.Calendar/]: Calendar = true, Daylight = true due to players logged in
Bumping this, version 7.2.0 afaik
I'm hosting a TerraFirmaGreg server, and my friend is having this crash issue but I am not. Only difference is I am wired up by ethernet directly to the server machine, and he is connecting over internet via a wireguard proxy I set up.
Strangely enough, sometimes the server doesn't see him as disconnected in spite of his game crashing to desktop, it only sees him as AFK. I don't have logs for that scenario though
Server logs show only a generic timeout message every time (this isnt the incident the crash log file aligns with, but it is the most recent time it has happened)
[22:42:37] [Server thread/INFO] [APTweaks(Core)/]: [APTweaks:Core] ↓ Server load changed from LOW (avg. 20.45918846130371) to VERY_LOW (avg. 17.12277603149414)
[22:42:54] [Server thread/INFO] [minecraft/ServerGamePacketListenerImpl]: getpwnedPJLadd lost connection: Timed out
[22:42:54] [Server thread/INFO] [minecraft/MinecraftServer]: getpwnedPJLadd left the game
[22:42:54] [Server thread/INFO] [ne.dr.tf.ut.ca.CalendarEventHandler/]: Player Logged Out - Checking for Calendar Updates.
[22:42:54] [Server thread/INFO] [ne.dr.tf.ut.ca.Calendar/]: Calendar = true, Daylight = true due to players logged in
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Listing events...
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Server Player Clone: 1
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Invalid Cloned Players: 1
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Server Player Logout: 5
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Listing memory leaks so far...
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: B: 3019MB / C: 3190MB / Diff: +171MB
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: Memory Leaks detected: (/atl force_refresh to update)
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: | Player:
[22:43:31] [Server thread/INFO] [de.un.al.AllTheLeaks/]: |- ServerPlayer (minecraft): 4
I agree with what MaxLevs said, if OP is correct on the cause of the bug, just make a check for the null pointer and stop execution without crashing, maybe try again with a delay.
Bumping to add a little more info that may or may not be relevant - I had my crashing friend try pinging the server IP using the command prompt (ping [ip] -n [couple of times]). There seemed to be a handful of packet drops right around the time of his crash. He's playing on wifi.