From c93308ebaeecb279424ca59e49cc2af404ad78c0 Mon Sep 17 00:00:00 2001 From: Ampitere Date: Wed, 29 May 2024 08:11:31 -0700 Subject: [PATCH] fix: map crash when counting trusts --- src/map/party.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/map/party.cpp b/src/map/party.cpp index b1706068bdc..ff1f686d523 100644 --- a/src/map/party.cpp +++ b/src/map/party.cpp @@ -335,7 +335,17 @@ void CParty::RemoveMember(CBattleEntity* PEntity) } } - auto trustCount = static_cast(m_PLeader)->PTrusts.size(); + size_t trustCount = 0; + if (m_PLeader != nullptr) + { + std::vector PTrusts = static_cast(m_PLeader)->PTrusts; + + if (!PTrusts.empty()) + { + trustCount = PTrusts.size(); + } + } + PChar->PLatentEffectContainer->CheckLatentsPartyMembers(members.size(), trustCount); PChar->pushPacket(new CPartyDefinePacket(nullptr)); @@ -854,8 +864,18 @@ void CParty::ReloadParty() else { RefreshFlags(info); - CBattleEntity* PLeader = GetLeader(); - auto trustCount = static_cast(PLeader)->PTrusts.size(); + CBattleEntity* PLeader = GetLeader(); + size_t trustCount = 0; + + if (PLeader != nullptr) + { + std::vector PTrusts = static_cast(PLeader)->PTrusts; + + if (!PTrusts.empty()) + { + trustCount = PTrusts.size(); + } + } // regular party for (auto& member : members)