Cleanup memory pool data on close

This commit is contained in:
Georg Hagen
2024-07-11 16:56:26 +02:00
parent 0fda5a0241
commit 888e30193b
3 changed files with 24 additions and 8 deletions

View File

@@ -26,16 +26,28 @@ namespace OpenVulkano::Vulkan
delete buffer;
}
MemoryPool::MemoryPool()
{
freeFunction = [this](ManagedBuffer* buffer) { this->FreeBuffer(buffer); };
MEM_POOLS.push_back(this);
Logger::RENDER->info("Created gpu memory pool");
}
MemoryPool::~MemoryPool()
{
if (!allocations.empty()) Close();
}
void MemoryPool::Close()
{
Utils::Remove(MEM_POOLS, this);
for(ManagedBuffer* buffer : recycleBuffers)
{
delete buffer;
}
recycleBuffers.clear();
for(auto& fF : toFree)
{
for(ManagedBuffer* buffer : fF)
{
delete buffer;
}
fF.clear();
}
allocations.clear();
Logger::RENDER->info("Destroyed gpu memory pool");
}
@@ -43,6 +55,7 @@ namespace OpenVulkano::Vulkan
{
device = dev;
toFree = decltype(toFree)(bufferCount);
MEM_POOLS.push_back(this);
}
void MemoryPool::StartFrame(uint64_t bufferId)