Skip to content

Commit

Permalink
fix memory leak when rl::sg::ode::Shape is destroyed (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahgnuoy authored Sep 13, 2024
1 parent a05e05a commit 4a8e401
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/rl/sg/ode/Shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace rl
::rl::sg::Shape(body),
geom(nullptr),
baseTransform(::rl::math::Transform::Identity()),
data(nullptr),
indices(),
transform(::rl::math::Transform::Identity()),
vertices()
Expand Down Expand Up @@ -92,9 +93,9 @@ namespace rl
callbackAction.addTriangleCallback(geometry->getTypeId(), Shape::triangleCallback, this);
callbackAction.apply(geometry);

::dTriMeshDataID data = ::dGeomTriMeshDataCreate();
this->data = ::dGeomTriMeshDataCreate();
::dGeomTriMeshDataBuildSimple(data, &this->vertices[0], this->vertices.size() / 4, &this->indices[0], this->indices.size());
this->geom = ::dCreateTriMesh(static_cast<Body*>(this->getBody())->space, data, nullptr, nullptr, nullptr);
this->geom = ::dCreateTriMesh(static_cast<Body*>(this->getBody())->space, this->data, nullptr, nullptr, nullptr);
}
else if (geometry->isOfType(::SoVRMLSphere::getClassTypeId()))
{
Expand All @@ -121,6 +122,7 @@ namespace rl
{
this->getBody()->remove(this);
::dGeomDestroy(this->geom);
::dGeomTriMeshDataDestroy(this->data);
}

::rl::math::Transform
Expand Down
2 changes: 2 additions & 0 deletions src/rl/sg/ode/Shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ namespace rl

::rl::math::Transform baseTransform;

::dTriMeshDataID data;

::std::vector<::dTriIndex> indices;

::rl::math::Transform transform;
Expand Down

0 comments on commit 4a8e401

Please sign in to comment.