Fix a memory leak (#5636)

This commit is contained in:
Dániel Juhász 2017-04-22 00:55:07 +02:00 committed by Loïc Blot
parent 3e71c8f482
commit 8464da7585
2 changed files with 15 additions and 12 deletions

View File

@ -387,37 +387,39 @@ void recalculateBoundingBox(scene::IMesh *src_mesh)
scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer) scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer)
{ {
scene::IMeshBuffer *clone = NULL;
switch (mesh_buffer->getVertexType()) { switch (mesh_buffer->getVertexType()) {
case video::EVT_STANDARD: { case video::EVT_STANDARD: {
video::S3DVertex *v = (video::S3DVertex *) mesh_buffer->getVertices(); video::S3DVertex *v = (video::S3DVertex *) mesh_buffer->getVertices();
u16 *indices = mesh_buffer->getIndices(); u16 *indices = mesh_buffer->getIndices();
scene::SMeshBuffer *temp_buf = new scene::SMeshBuffer(); scene::SMeshBuffer *cloned_buffer = new scene::SMeshBuffer();
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
return temp_buf; return cloned_buffer;
break;
} }
case video::EVT_2TCOORDS: { case video::EVT_2TCOORDS: {
video::S3DVertex2TCoords *v = video::S3DVertex2TCoords *v =
(video::S3DVertex2TCoords *) mesh_buffer->getVertices(); (video::S3DVertex2TCoords *) mesh_buffer->getVertices();
u16 *indices = mesh_buffer->getIndices(); u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents(); scene::SMeshBufferTangents *cloned_buffer =
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, new scene::SMeshBufferTangents();
cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
break; return cloned_buffer;
} }
case video::EVT_TANGENTS: { case video::EVT_TANGENTS: {
video::S3DVertexTangents *v = video::S3DVertexTangents *v =
(video::S3DVertexTangents *) mesh_buffer->getVertices(); (video::S3DVertexTangents *) mesh_buffer->getVertices();
u16 *indices = mesh_buffer->getIndices(); u16 *indices = mesh_buffer->getIndices();
scene::SMeshBufferTangents *temp_buf = new scene::SMeshBufferTangents(); scene::SMeshBufferTangents *cloned_buffer =
temp_buf->append(v, mesh_buffer->getVertexCount(), indices, new scene::SMeshBufferTangents();
cloned_buffer->append(v, mesh_buffer->getVertexCount(), indices,
mesh_buffer->getIndexCount()); mesh_buffer->getIndexCount());
break; return cloned_buffer;
} }
} }
return clone; // This should not happen.
sanity_check(false);
return NULL;
} }
scene::SMesh* cloneMesh(scene::IMesh *src_mesh) scene::SMesh* cloneMesh(scene::IMesh *src_mesh)

View File

@ -85,6 +85,7 @@ void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
/* /*
* Clone the mesh buffer. * Clone the mesh buffer.
* The returned pointer should be dropped.
*/ */
scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer); scene::IMeshBuffer* cloneMeshBuffer(scene::IMeshBuffer *mesh_buffer);