From 3ffdbff34eb0f8834c2e68aef075c104899ac71f Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sun, 18 Feb 2024 19:45:37 -0600 Subject: [PATCH 1/3] Check for a nullptr/dead object in aiBestNearestTarget() --- src/ai.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ai.cpp b/src/ai.cpp index 745ed3d1a07..42ae2fde79d 100644 --- a/src/ai.cpp +++ b/src/ai.cpp @@ -604,6 +604,11 @@ int aiBestNearestTarget(DROID *psDroid, BASE_OBJECT **ppsObj, int weapon_slot, i BASE_OBJECT *friendlyObj = nullptr; BASE_OBJECT *targetInQuestion = *gi; + if (targetInQuestion == nullptr || isDead(targetInQuestion)) + { + continue; + } + /* This is a friendly unit, check if we can reuse its target */ if (aiCheckAlliances(targetInQuestion->player, psDroid->player)) { From cd03b07ab4722417db82277009445fb35ba3bf19 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sun, 18 Feb 2024 19:53:38 -0600 Subject: [PATCH 2/3] Check for nullptr/dead lassat in countUpdate() --- src/loop.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/loop.cpp b/src/loop.cpp index 9d64d8759b8..71d505b1917 100644 --- a/src/loop.cpp +++ b/src/loop.cpp @@ -460,7 +460,11 @@ void countUpdate(bool synch) setLasSatExists(false, i); for (const STRUCTURE *psCBuilding : apsStructLists[i]) { - if (psCBuilding->pStructureType->type == REF_SAT_UPLINK && psCBuilding->status == SS_BUILT) + if (psCBuilding == nullptr || isDead(psCBuilding)) + { + continue; + } + if (psCBuilding->pStructureType && psCBuilding->pStructureType->type == REF_SAT_UPLINK && psCBuilding->status == SS_BUILT) { setSatUplinkExists(true, i); } @@ -472,7 +476,11 @@ void countUpdate(bool synch) } for (const STRUCTURE *psCBuilding : mission.apsStructLists[i]) { - if (psCBuilding->pStructureType->type == REF_SAT_UPLINK && psCBuilding->status == SS_BUILT) + if (psCBuilding == nullptr || isDead(psCBuilding)) + { + continue; + } + if (psCBuilding->pStructureType && psCBuilding->pStructureType->type == REF_SAT_UPLINK && psCBuilding->status == SS_BUILT) { setSatUplinkExists(true, i); } From ea751abbf65f9b38dd5e7ba16894546c96d0d4f2 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sun, 18 Feb 2024 20:21:29 -0600 Subject: [PATCH 3/3] Fix potential crash when recording end game unit stats --- src/droid.cpp | 8 ++++++++ src/scores.cpp | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/droid.cpp b/src/droid.cpp index 970cf33b9ce..237868c1b14 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -2279,12 +2279,20 @@ UDWORD getNumDroidsForLevel(uint32_t player, UDWORD level) } for (const DROID* psDroid : *dList) { + if (psDroid == nullptr || isDead(psDroid)) + { + continue; + } if (getDroidLevel(psDroid) == level) { ++count; } if (psDroid->isTransporter()) { + if (psDroid->psGroup == nullptr) + { + continue; + } for (const DROID *psCurr : psDroid->psGroup->psList) { if (psCurr != psDroid && getDroidLevel(psCurr) == level) diff --git a/src/scores.cpp b/src/scores.cpp index ef32fc5e015..70e12a5843c 100644 --- a/src/scores.cpp +++ b/src/scores.cpp @@ -310,8 +310,17 @@ END_GAME_STATS_DATA collectEndGameStatsData() } for (const DROID* psDroid : *dList) { + if (psDroid == nullptr || isDead(psDroid)) + { + continue; + } + ++fullStats.numUnits; if (psDroid->isTransporter()) { + if (psDroid->psGroup == nullptr) + { + continue; + } for (DROID *psCurr : psDroid->psGroup->psList) { if (psCurr != psDroid) @@ -320,7 +329,6 @@ END_GAME_STATS_DATA collectEndGameStatsData() } } } - ++fullStats.numUnits; } } while (++idx < 3); }