Hi, I started using this library yesterday to help with my undergrad dissertation. I've been enjoying the library but getting tons of segmentation faults. I'm on macOS 10.15.7 using XCode.
tid_307 (1): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
This was very prevalent with my first implementation of the physics code. I need to test whether bunch of voxels collide with a mesh, so was creating a box shape and collider body for each voxel. This code produced tons of segmentation faults.
I've since changed the code to use one box shape and collider, and purely move the transform to each voxel. However, with this change I now get an assertion fail:
assert(contactPoints[i].size() == 0);
This assertion only triggers on the 5th/6th voxel, however, which makes the problem even stranger. However, I assume it just happens that the 5th/6th voxel is actually colliding so there's a difference in the methods. Ie, for the first few voxels, there's no collision so no contact points. But for the 5th or 6th, it's colliding so there are collision points.
And if I comment out the assertion, I get more segmentation faults from this code.
mCollidersComponents.mCollisionShapes[i]->computeAABB(aabb, transform * mCollidersComponents.mLocalToBodyTransforms[i]);
To note about the segmentation faults, they've happened in multiple places and it doesn't seem to be one problematic line of code. However, there seems to be a similarity in that it's related to the entity component system / pointers to entities.
Segmentation Fault Stack Trace
#0 0x000000015184d383 in reactphysics3d::BroadPhaseSystem::updateCollidersComponents(unsigned int, unsigned int, float) at OpenPL/External/ReactPhysics3D/src/systems/BroadPhaseSystem.cpp:180
#1 0x000000015184d0fc in reactphysics3d::BroadPhaseSystem::updateCollider(reactphysics3d::Entity, float) at OpenPL/External/ReactPhysics3D/src/systems/BroadPhaseSystem.cpp:122
#2 0x00000001517b4894 in reactphysics3d::CollisionDetectionSystem::updateCollider(reactphysics3d::Entity, float) at OpenPL/External/ReactPhysics3D/include/reactphysics3d/systems/CollisionDetectionSystem.h:435
#3 0x00000001517b46de in reactphysics3d::CollisionBody::updateBroadPhaseState(float) const at OpenPL/External/ReactPhysics3D/src/body/CollisionBody.cpp:233
#4 0x00000001517b543d in reactphysics3d::CollisionBody::setTransform(reactphysics3d::Transform const&) at OpenPL/External/ReactPhysics3D/src/body/CollisionBody.cpp:398
#5 0x0000000151892065 in PL_SCENE::FillVoxels() at OpenPL/Source/Private/Objects/Private/PL_SCENE.cpp:415
#6 0x00000001518907b8 in PL_SCENE::Voxelise(PLVector, PLVector, float) at OpenPL/Source/Private/Objects/Private/PL_SCENE.cpp:308
#7 0x00000001519f7406 in ::PL_Scene_Voxelise(PL_SCENE *, PLVector *, PLVector *, float) at OpenPL/Source/Private/OpenPL.cpp:109
Assertion Stack Trace
#4 0x0000000156f21aa8 in reactphysics3d::NarrowPhaseInfoBatch::clear() at OpenPL/External/ReactPhysics3D/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp:133
#5 0x0000000156f2033a in reactphysics3d::NarrowPhaseInfoBatch::~NarrowPhaseInfoBatch() at OpenPL/External/ReactPhysics3D/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp:47
#6 0x0000000156f20545 in reactphysics3d::NarrowPhaseInfoBatch::~NarrowPhaseInfoBatch() at OpenPL/External/ReactPhysics3D/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp:46
#7 0x0000000156f87416 in reactphysics3d::NarrowPhaseInput::~NarrowPhaseInput() at OpenPL/External/ReactPhysics3D/include/reactphysics3d/collision/narrowphase/NarrowPhaseInput.h:54
#8 0x0000000156f86a05 in reactphysics3d::NarrowPhaseInput::~NarrowPhaseInput() at OpenPL/External/ReactPhysics3D/include/reactphysics3d/collision/narrowphase/NarrowPhaseInput.h:54
#9 0x0000000156f9f7df in reactphysics3d::CollisionDetectionSystem::testOverlap(reactphysics3d::CollisionBody*, reactphysics3d::CollisionBody*) at OpenPL/External/ReactPhysics3D/src/systems/CollisionDetectionSystem.cpp:1478
#10 0x0000000156f803be in reactphysics3d::PhysicsWorld::testOverlap(reactphysics3d::CollisionBody*, reactphysics3d::CollisionBody*) at OpenPL/External/ReactPhysics3D/src/engine/PhysicsWorld.cpp:303
#11 0x0000000156fd9068 in PL_SCENE::FillVoxels() at OpenPL/Source/Private/Objects/Private/PL_SCENE.cpp:419
#12 0x0000000156fd7798 in PL_SCENE::Voxelise(PLVector, PLVector, float) at OpenPL/Source/Private/Objects/Private/PL_SCENE.cpp:308
#13 0x000000015713e3e6 in ::PL_Scene_Voxelise(PL_SCENE *, PLVector *, PLVector *, float) at OpenPL/Source/Private/OpenPL.cpp:109
The code is slightly stripped down but still contains the core logic.
// Create box collider at origin. Will get moved later
CollisionBody* VoxelBody = PhysicsWorld->createCollisionBody(Transform::identity());
BoxShape* VoxelShape = PhysicsSystem->createBoxShape(Vector3(VoxelHalfSize, VoxelHalfSize, VoxelHalfSize));
std::unique_ptr<TriangleVertexArray> TriangleArray (new TriangleVertexArray(static_cast<unsigned int>(Mesh.Vertices.cols()),
3 * sizeof(double),
3 * sizeof(int),
TriangleMesh* TriangleMesh = PhysicsSystem->createTriangleMesh();
ConcaveMeshShape* ConcaveMesh = PhysicsSystem->createConcaveMeshShape(TriangleMesh);
CollisionBody* MeshBody = PhysicsWorld->createCollisionBody(Transform::identity());
for (int i = 0; i < MeshCells->size(); i++)
auto& Cell = (*MeshCells.get())[i];
Eigen::Vector3d Pos = Cell->WorldPosition;
Transform VoxelTransform = Transform::identity();
VoxelTransform.setPosition(Vector3(Pos.x(), Pos.y(), Pos.z()));
if (PhysicsWorld->testOverlap(MeshBody, VoxelBody))
Cell->Absorptivity = 0.75f; // DEBUG. TODO: Fill this with an actual value
I've just done a little more testing and there are no problems if I use a box shape for the mesh body. It seems the concave mesh shape is the problem.
I understand concave mesh collision is expensive but I was hoping to have a "one size fits all" solution. As time isn't really a concern, I hoped a concave mesh could work for all meshes I throw at it.
You can view my roughly up to date code at: https://github.com/KarateKidzz/OpenPL