diff options
author | erorcun <erorcunerorcun@hotmail.com.tr> | 2021-07-02 22:56:31 +0200 |
---|---|---|
committer | erorcun <erorcunerorcun@hotmail.com.tr> | 2021-07-02 22:56:54 +0200 |
commit | 4eea98c66b86f444eb07e730ce7a3118dfd092c1 (patch) | |
tree | 537bc4052e11c1dc9f590d745430226d5bcceb71 /src/peds/Ped.cpp | |
parent | Fix use of integer in RemoveBuildingsNotInArea call (diff) | |
download | re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar.gz re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar.bz2 re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar.lz re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar.xz re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.tar.zst re3-4eea98c66b86f444eb07e730ce7a3118dfd092c1.zip |
Diffstat (limited to 'src/peds/Ped.cpp')
-rw-r--r-- | src/peds/Ped.cpp | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index e07b5dd4..96f3479c 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -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 |