diff --git a/src/Components/Modules/ModelSurfs.cpp b/src/Components/Modules/ModelSurfs.cpp index ec607c77..8a40d4b4 100644 --- a/src/Components/Modules/ModelSurfs.cpp +++ b/src/Components/Modules/ModelSurfs.cpp @@ -109,6 +109,19 @@ namespace Components Game::XSurface* tempSurfaces = allocator.allocateArray(modelSurfs->numSurfaces); char* surfaceData = reinterpret_cast(modelSurfs->surfaces); + if (ModelSurfs::AllocMap.find(modelSurfs->name) != ModelSurfs::AllocMap.end()) + { + Game::CModelAllocData* allocData = ModelSurfs::AllocMap[modelSurfs->name]; + + if (allocData) + { + Utils::Memory::FreeAlign(allocData->indexBuffer); + Utils::Memory::FreeAlign(allocData->vertexBuffer); + Utils::Memory::Free(allocData->mainArray); + Utils::Memory::Free(allocData); + } + } + ModelSurfs::AllocMap[modelSurfs->name] = allocationData; *reinterpret_cast(reinterpret_cast(allocationData->mainArray) + 44) = allocationData;