From 6842c94306c7503a0758f82d4d1a429ee3dff088 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Thu, 13 Jun 2024 23:22:56 +0300 Subject: [PATCH] Fix missing resize for m_buildingPool --- Client/game_sa/CBuildingsPoolSA.cpp | 14 ++++++++------ Client/game_sa/CBuildingsPoolSA.h | 4 ++-- Client/game_sa/CPoolSAInterface.h | 13 +++++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Client/game_sa/CBuildingsPoolSA.cpp b/Client/game_sa/CBuildingsPoolSA.cpp index 6f15dc87e1..eacfc1e1f9 100644 --- a/Client/game_sa/CBuildingsPoolSA.cpp +++ b/Client/game_sa/CBuildingsPoolSA.cpp @@ -40,7 +40,7 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding if (dwElementIndexInPool == UINT_MAX) return false; - m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding}; + m_buildingPool.entities[dwElementIndexInPool] = {pBuilding, (CClientEntity*)pClientBuilding}; // Increase the count of objects ++m_buildingPool.ulCount; @@ -108,8 +108,8 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding) modelInfo->RemoveColRef(); // Remove from BuildingSA pool - auto* pBuildingSA = m_buildingPool.arrayOfClientEntities[dwElementIndexInPool].pEntity; - m_buildingPool.arrayOfClientEntities[dwElementIndexInPool] = {nullptr, nullptr}; + auto* pBuildingSA = m_buildingPool.entities[dwElementIndexInPool].pEntity; + m_buildingPool.entities[dwElementIndexInPool] = {nullptr, nullptr}; // Delete it from memory delete pBuildingSA; @@ -191,7 +191,9 @@ void CBuildingsPoolSA::RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding) bool CBuildingsPoolSA::Resize(int size) { auto* pool = (*m_ppBuildingPoolInterface); - const int curretnSize = pool->m_nSize; + const int currentSize = pool->m_nSize; + + m_buildingPool.entities.resize(size); void* oldPool = pool->m_pObjects; @@ -210,7 +212,7 @@ bool CBuildingsPoolSA::Resize(int size) CBuildingSAInterface* newObjects = MemSA::malloc_struct(size); if (newObjects == nullptr) { - Resize(curretnSize); + Resize(currentSize); return false; } @@ -218,7 +220,7 @@ bool CBuildingsPoolSA::Resize(int size) if (newBytemap == nullptr) { MemSA::free(newObjects); - Resize(curretnSize); + Resize(currentSize); return false; } diff --git a/Client/game_sa/CBuildingsPoolSA.h b/Client/game_sa/CBuildingsPoolSA.h index 9f38202243..7ae69d90e0 100644 --- a/Client/game_sa/CBuildingsPoolSA.h +++ b/Client/game_sa/CBuildingsPoolSA.h @@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool void RemovePedsContactEnityLinks(); private: - SPoolData m_buildingPool; - CPoolSAInterface** m_ppBuildingPoolInterface; + SVectorPoolData m_buildingPool{MAX_BUILDINGS}; + CPoolSAInterface** m_ppBuildingPoolInterface; std::unique_ptr, MAX_BUILDINGS>> m_pOriginalBuildingsBackup; }; diff --git a/Client/game_sa/CPoolSAInterface.h b/Client/game_sa/CPoolSAInterface.h index 8b653aefc1..a689830f4a 100644 --- a/Client/game_sa/CPoolSAInterface.h +++ b/Client/game_sa/CPoolSAInterface.h @@ -149,3 +149,16 @@ struct SPoolData } } }; + +template +struct SVectorPoolData +{ + std::vector> entities; + unsigned long ulCount; + +public: + SVectorPoolData(size_t defaultSize) : ulCount(0UL) + { + entities.resize(defaultSize, {nullptr, nullptr}); + } +};