Comments (1)
Hello,
The rule is the following one for cleaning up allocated objects : If you have allocated memory by yourself (using the new operator), you need to clean this memory by yourself (with the delete operator). Otherwise, the memory has been allocated by the physics engine and will be released by the physics engine.
You can find an example of the creation of a concave mesh shape in the testbed application here :
https://github.com/DanielChappuis/reactphysics3d/blob/master/testbed/common/ConcaveMesh.cpp
In this example you can see that I create some TriangleVertexArray as in the following code :
// For each subpart of the mesh
for (unsigned int i=0; i<getNbParts(); i++) {
// Vertex and Indices array for the triangle mesh
rp3d::TriangleVertexArray* vertexArray = new rp3d::TriangleVertexArray(.....);
// Add the triangle vertex array of the subpart to the triangle mesh
triangleMesh.addSubpart(vertexArray);
}
As you can see, I allocate memory by myself with the "new" operator. Therefore, I am responsible to delete this memory. I do it with the following code :
// Destroy the triangle vertex arrays
for (unsigned int i=0; i<triangleMesh.getNbSubparts(); i++) {
delete triangleMesh.getSubpart(i);
}
I also create the ConcaveMeshShape with the "new" operator as follows :
// Create the collision shape
concaveShape = new rp3d::ConcaveMeshShape(&triangleMesh);
Therefore I have to delete this shape at the end like this :
delete concaveShape;
Note that when you add a collision shape to a body, you get back a pointer to the proxy shape as you can see with this code :
// Add a collision shape to the body
proxyShape = body->addCollisionShape(concaveShape, rp3d::Transform::identity(), mass);
As you can see, you have not allocated memory for the proxy shape by yourself here (no new operator). This memory has been allocated by the physics engine. Therefore, you do not need to delete this object by yourself. The proxy shape will be deleted by the physics engine when you remove the proxy shape from the body or you destroy the body.
I hope this helps.
from reactphysics3d.
Related Issues (20)
- How to get axis angles? HOT 4
- CollisionDetectionSystem::createContacts() assert crash HOT 2
- Transform::getOpenGLMatrix not including rotation HOT 2
- void PhysicsWorld::createIslands() dirty contactPairIndex crash HOT 4
- Will it work for Android? HOT 2
- testbed build error with glDisableVertexAttribArray HOT 1
- Build failing - Missing include in configuration.h HOT 3
- Assertion failed in OverlappingPairs, version release 0.10.0 HOT 5
- Destroying an empty physics world leads to assertion failure (after upgrading to 0.10.0) HOT 2
- 0.10.0 - Raycasting gives incorrect results for HeightFieldShape when scaling factor is applied HOT 2
- Child somewhat-static collision shape HOT 1
- Ticking different objects at different rates HOT 1
- v0.10.0: Assertion Failed in NarrowPhaseInfoBatch::addContactPoint() HOT 2
- Why is the collision not happening how I think it should? HOT 3
- 0.10.0 - createConvexMeshShape example provided in manual doesn't work HOT 4
- find mistake in code HOT 2
- Rigid bodies without colliders escape from joint with a rigid body with collider. HOT 2
- ConvexMeshShape issue (assert) HOT 1
- Failed assertion in OverlappingPairs::setNeedToTestOverlap in v0.10.1 HOT 2
- Is there any way to get angular rotation relative to an object?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactphysics3d.