From a307f0601a84e4361461d3a5baf15b784b093d2f Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Mon, 8 Jun 2026 21:22:04 -0700 Subject: [PATCH] fix: bugs in private instances causing master crashes (#1986) * fix: bugs in private instances causing master crashes tested that creating a private instance and shutting down the server no longer crashes master * Update InstanceManager.cpp --- dMasterServer/InstanceManager.cpp | 7 ++++++- dMasterServer/InstanceManager.h | 1 + dMasterServer/MasterServer.cpp | 10 ++++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dMasterServer/InstanceManager.cpp b/dMasterServer/InstanceManager.cpp index c2ab3333..6ddd32d5 100644 --- a/dMasterServer/InstanceManager.cpp +++ b/dMasterServer/InstanceManager.cpp @@ -332,6 +332,12 @@ int InstanceManager::GetHardCap(LWOMAPID mapID) { return zone ? zone->population_hard_cap : 12; } +void InstanceManager::PruneUnreadyInstances() { + for (int i = static_cast(m_Instances.size()) - 1; i >= 0; i--) { + if (!m_Instances[i]->GetIsReady()) m_Instances.erase(m_Instances.cbegin() + i); + } +} + void Instance::SetShutdownComplete(const bool value) { m_Shutdown = value; } @@ -359,4 +365,3 @@ bool Instance::IsFull(bool isFriendTransfer) const { return true; } - diff --git a/dMasterServer/InstanceManager.h b/dMasterServer/InstanceManager.h index a6ba6d9a..5481efbc 100644 --- a/dMasterServer/InstanceManager.h +++ b/dMasterServer/InstanceManager.h @@ -133,6 +133,7 @@ public: const InstancePtr& CreatePrivateInstance(LWOMAPID mapID, LWOCLONEID cloneID, const std::string& password); const InstancePtr& FindPrivateInstance(const std::string& password); void SetIsShuttingDown(bool value) { this->m_IsShuttingDown = value; }; + void PruneUnreadyInstances(); private: std::string mExternalIP; diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 0ae71f07..4fd89fbe 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -665,7 +665,7 @@ void HandlePacket(Packet* packet) { inStream.Read(theirInstanceID); const auto& instance = - Game::im->FindInstance(theirZoneID, theirInstanceID); + Game::im->FindInstanceWithPrivate(theirZoneID, theirInstanceID); if (instance) { instance->AddPlayer(Player()); } else { @@ -762,7 +762,7 @@ void HandlePacket(Packet* packet) { LOG("Got world ready %i %i", zoneID, instanceID); - const auto& instance = Game::im->FindInstance(zoneID, instanceID); + const auto& instance = Game::im->FindInstanceWithPrivate(zoneID, instanceID); if (instance == nullptr) { LOG("Failed to find zone to ready"); @@ -858,13 +858,11 @@ int ShutdownSequence(int32_t signal) { } // A server might not be finished spinning up yet, remove all of those here. + // prune the unready ones before looping over all of them + Game::im->PruneUnreadyInstances(); for (const auto& instance : Game::im->GetInstances()) { if (!instance) continue; - if (!instance->GetIsReady()) { - Game::im->RemoveInstance(instance); - } - instance->SetIsShuttingDown(true); }