Skip to content

Commit

Permalink
Fix missing resize for m_buildingPool
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Jun 13, 2024
1 parent 90cd020 commit e079836
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 8 additions & 6 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -210,15 +212,15 @@ bool CBuildingsPoolSA::Resize(int size)
CBuildingSAInterface* newObjects = MemSA::malloc_struct<CBuildingSAInterface>(size);
if (newObjects == nullptr)
{
Resize(curretnSize);
Resize(currentSize);
return false;
}

tPoolObjectFlags* newBytemap = MemSA::malloc_struct<tPoolObjectFlags>(size);
if (newBytemap == nullptr)
{
MemSA::free(newObjects);
Resize(curretnSize);
Resize(currentSize);
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool
void RemovePedsContactEnityLinks();

private:
SPoolData<CBuildingSA, CBuildingSAInterface, MAX_BUILDINGS> m_buildingPool;
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;
SVectorPoolData<CBuildingSA, CBuildingSAInterface> m_buildingPool{MAX_BUILDINGS};
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;

std::unique_ptr<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>> m_pOriginalBuildingsBackup;
};
13 changes: 13 additions & 0 deletions Client/game_sa/CPoolSAInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,16 @@ struct SPoolData
}
}
};

template <class T, class I>
struct SVectorPoolData
{
std::vector<SClientEntity<T>> entities;
unsigned long ulCount;

public:
SVectorPoolData(size_t defaultSize) : ulCount(0UL)
{
entities.resize(defaultSize, {nullptr, nullptr});
}
};

0 comments on commit e079836

Please sign in to comment.