From 0a8b0cb4068483129e26ff058c3d667e49904ed5 Mon Sep 17 00:00:00 2001 From: izzy Date: Sat, 7 Mar 2026 17:40:14 -0500 Subject: [PATCH] fix: impl shutdown error handling --- Minecraft.Client/ClientConnection.cpp | 29 +++++++++++++++-- Minecraft.World/Connection.cpp | 46 ++++++++++++++------------- 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 9b955cae9..572774fac 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -151,8 +151,33 @@ ClientConnection::~ClientConnection() void ClientConnection::tick() { - if (!done) connection->tick(); - connection->flush(); + if (done) return; + + try + { + connection->tick(); + connection->flush(); + } + catch (const IOException &e) + { + app.DebugPrintf("IOException - %ls\n", e.information.c_str()); + this->done; + } + catch (const RuntimeException &e) + { + app.DebugPrintf("RuntimeException - %ls\n", e.information.c_str()); + this->done; + } + catch (const IllegalArgumentException &e) + { + app.DebugPrintf("IllegalArgumentException - %ls\n", e.information.c_str()); + this->done; + } + catch (const EOFException &e) + { + app.DebugPrintf("EOFException - %ls\n", e.information.c_str()); + this->done; + } } INetworkPlayer *ClientConnection::getNetworkPlayer() diff --git a/Minecraft.World/Connection.cpp b/Minecraft.World/Connection.cpp index 09f72be09..d6e7fdfc7 100644 --- a/Minecraft.World/Connection.cpp +++ b/Minecraft.World/Connection.cpp @@ -583,30 +583,32 @@ int Connection::runRead(void* lpParam) con->readThreads++; LeaveCriticalSection(cs); - //try { + try { + MemSect(19); + while (con->running && !con->quitting && ShutdownManager::ShouldRun(ShutdownManager::eConnectionReadThreads)) + { + while (con->readTick()) + ; - MemSect(19); - while (con->running && !con->quitting && ShutdownManager::ShouldRun(ShutdownManager::eConnectionReadThreads)) - { - while (con->readTick()) - ; - - // try { - //Sleep(100L); - // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well - con->m_hWakeReadThread->WaitForSignal(100L); + // try { + //Sleep(100L); + // TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well + con->m_hWakeReadThread->WaitForSignal(100L); + } + MemSect(0); } - MemSect(0); - - /* 4J JEV, removed try/catch - } catch (InterruptedException e) { - } - } - } finally { - synchronized (threadCounterLock) { - readThreads--; - } - } */ + catch (EOFException e) + { + app.DebugPrintf("EOFException - %ls\n", e.information.c_str()); + con->running = false; + con->quitting = true; + } + catch (IOException e) + { + app.DebugPrintf("IOException - %ls\n", e.information.c_str()); + con->running = false; + con->quitting = true; + } ShutdownManager::HasFinished(ShutdownManager::eConnectionReadThreads); return 0;