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)) { 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/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); } 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); }