Skip to content

Commit

Permalink
#150 Fix leak memory, crash on render mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Jul 19, 2022
1 parent bd7b156 commit 9cdc18e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions Projects/Skylicht/Engine/Source/RenderMesh/CRenderMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace Skylicht
{
renderer->unusedMaterial(m);
}

m->drop();
}
m_materials.clear();
Expand Down
14 changes: 13 additions & 1 deletion Projects/Skylicht/Engine/Source/RenderMesh/CRenderMeshData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ namespace Skylicht
if (materialName == name)
{
material->addAffectMesh(mesh->getMeshBuffer(bufferID));

if (mesh->Materials[bufferID])
mesh->Materials[bufferID]->drop();

mesh->Materials[bufferID] = material;
mesh->Materials[bufferID]->grab();
}

bufferID++;
Expand All @@ -118,7 +123,12 @@ namespace Skylicht
if (materialName == name)
{
material->removeAffectMesh(mesh->getMeshBuffer(bufferID));
mesh->Materials[bufferID] = NULL;

if (mesh->Materials[bufferID])
{
mesh->Materials[bufferID]->drop();
mesh->Materials[bufferID] = NULL;
}
}

bufferID++;
Expand Down Expand Up @@ -163,6 +173,8 @@ namespace Skylicht
meshBuffer->getBoundingBox() = originalMeshBuffer->getBoundingBox();

mesh->replaceMeshBuffer(i, meshBuffer);

meshBuffer->drop();
}

mesh->setHardwareMappingHint(EHM_STREAM, EBT_VERTEX);
Expand Down
7 changes: 4 additions & 3 deletions Projects/Skylicht/Engine/Source/RenderMesh/CSkinnedMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ namespace Skylicht
{
CSkinnedMesh* newMesh = new CSkinnedMesh();
newMesh->BoundingBox = BoundingBox;
newMesh->MaterialName = MaterialName;
newMesh->Materials = Materials;
newMesh->Joints = Joints;

for (u32 i = 0, n = MeshBuffers.size(); i < n; i++)
{
newMesh->addMeshBuffer(MeshBuffers[i]);
newMesh->addMeshBuffer(
MeshBuffers[i],
MaterialName[i].c_str(),
Materials[i]);
}

for (u32 i = 0, n = BlendShape.size(); i < n; i++)
Expand Down

0 comments on commit 9cdc18e

Please sign in to comment.