Fix memory leak [skip ci]
parent
082b5ea1f1
commit
87f5136714
|
@ -431,8 +431,7 @@ MeshCombiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdString,
|
|||
partCache.previewVertices.clear();
|
||||
partCache.isSuccessful = false;
|
||||
partCache.joined = (target == PartTarget::Model && !isDisabled);
|
||||
delete partCache.mesh;
|
||||
partCache.mesh = nullptr;
|
||||
partCache.releaseMeshes();
|
||||
|
||||
struct NodeInfo
|
||||
{
|
||||
|
@ -1471,6 +1470,7 @@ void MeshGenerator::generate()
|
|||
}
|
||||
m_cacheContext->partMirrorIdMap.erase(mirrorFrom);
|
||||
}
|
||||
it->second.releaseMeshes();
|
||||
it = m_cacheContext->parts.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
@ -1487,6 +1487,7 @@ void MeshGenerator::generate()
|
|||
}
|
||||
combinationIt++;
|
||||
}
|
||||
it->second.releaseMeshes();
|
||||
it = m_cacheContext->components.erase(it);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,13 @@ class GeneratedPart
|
|||
public:
|
||||
~GeneratedPart()
|
||||
{
|
||||
delete mesh;
|
||||
releaseMeshes();
|
||||
};
|
||||
void releaseMeshes()
|
||||
{
|
||||
delete mesh;
|
||||
mesh = nullptr;
|
||||
}
|
||||
MeshCombiner::Mesh *mesh = nullptr;
|
||||
std::vector<QVector3D> vertices;
|
||||
std::vector<std::vector<size_t>> faces;
|
||||
|
@ -63,6 +68,15 @@ public:
|
|||
class GeneratedCacheContext
|
||||
{
|
||||
public:
|
||||
~GeneratedCacheContext()
|
||||
{
|
||||
for (auto &it: cachedCombination)
|
||||
delete it.second;
|
||||
for (auto &it: parts)
|
||||
it.second.releaseMeshes();
|
||||
for (auto &it: components)
|
||||
it.second.releaseMeshes();
|
||||
}
|
||||
std::map<QString, GeneratedComponent> components;
|
||||
std::map<QString, GeneratedPart> parts;
|
||||
std::map<QString, QString> partMirrorIdMap;
|
||||
|
|
Loading…
Reference in New Issue