From 91fb368b74f8915d3ab4d73bed18512b770f8e75 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Sun, 18 Feb 2024 20:21:29 -0600 Subject: [PATCH] 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); }