Peds: Efforts to find the reason of crashes on GCC 7.5.0

* Prevent deleted peds to be in nearPeds list (was always needed, might be unrelated to crashes)
* Add asserts to nearPeds and PedIK ctor (crash reasons)
* Shouldn't fix reported crashes since they were caused by null peds.
This commit is contained in:
erorcun
2021-07-02 23:56:31 +03:00
parent 987e09515b
commit 4eea98c66b
4 changed files with 30 additions and 7 deletions

View File

@@ -403,6 +403,30 @@ CPed::~CPed(void)
CPopulation::NumMiamiViceCops--;
CPopulation::UpdatePedCount((ePedType)m_nPedType, true);
DMAudio.DestroyEntity(m_audioEntityId);
// Because of the nature of ped lists in GTA, it can sometimes be outdated.
// Remove ourself from nearPeds list of the Peds in our nearPeds list.
#ifdef FIX_BUGS
for(int i = 0; i < m_numNearPeds; i++) {
CPed *nearPed = m_nearPeds[i];
assert(nearPed != nil);
if (!nearPed->IsPointerValid())
continue;
for(int j = 0; j < nearPed->m_numNearPeds;) {
assert(j == ARRAY_SIZE(m_nearPeds) - 1 || nearPed->m_nearPeds[j] || !nearPed->m_nearPeds[j+1]); // ensure nil comes after nil
if (nearPed->m_nearPeds[j] == this) {
for (int k = j; k < ARRAY_SIZE(m_nearPeds) - 1; k++) {
nearPed->m_nearPeds[k] = nearPed->m_nearPeds[k + 1];
nearPed->m_nearPeds[k + 1] = nil;
}
nearPed->m_numNearPeds--;
} else
j++;
}
}
#endif
}
void
@@ -519,13 +543,15 @@ CPed::BuildPedLists(void)
removePed = true;
}
}
assert(i == ARRAY_SIZE(m_nearPeds) - 1 || m_nearPeds[i] || !m_nearPeds[i+1]); // ensure nil comes after nil
if (removePed) {
// If we arrive here, the ped we're checking isn't "near", so we should remove it.
for (int j = i; j < ARRAY_SIZE(m_nearPeds) - 1; j++) {
m_nearPeds[j] = m_nearPeds[j + 1];
m_nearPeds[j + 1] = nil;
}
// Above loop won't work on last slot, so we need to empty it.
m_nearPeds[ARRAY_SIZE(m_nearPeds) - 1] = nil;
m_numNearPeds--;
} else