DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.54k stars 223 forks source link

Matrix3x3 getInverse assert, v0.7.0 #82

Closed aliasdevelopment closed 5 years ago

aliasdevelopment commented 5 years ago

Hi Daniel

This happens when I add addCollisionShape to a BoxShape when the extend is small. Got allot of boxes of different sizes which do not assert, but when I added a somewhat small box I get this assert.

box_extend = {x = 0.100000001, y = 0.0250000004, z = 0.100000001}

GDB output:

(gdb) frame 7

7 0x0000000000443828 in general::reactphysics::create_box (this=0x9a15e8, object_data=std::shared_ptr (use count 1, weak count 0) = {...}, extend=..., mass=@0x7fffffffc828: 1,

dynamic=@0x7fffffffc82f: false) at /home/projects/test/applications/general/physics/react.hpp:68

68 body->addCollisionShape( shape.get(), shape_transform, shape_mass ); (gdb) info locals initPosition_internal = {x = 0, y = 0, z = 0.00999999978} initOrientation = {x = 0, y = 0, z = 0, w = 1} transform = {mPosition = {x = 0, y = 0, z = 0.00999999978}, mOrientation = {x = 0, y = 0, z = 0, w = 1}} pos_transform = @0x7fffffffc660: {x = 0, y = 0, z = 0.00999999978} orientation_transform = @0x7fffffffc66c: {x = 0, y = 0, z = 0, w = 1} box_extend = {x = 0.100000001, y = 0.0250000004, z = 0.100000001} shape = std::unique_ptr = {get() = 0x12f3120} shape_mass = 1 shape_transform = {mPosition = {x = 0, y = 0, z = 0}, mOrientation = {x = 0, y = 0, z = 0, w = 1}} body = std::unique_ptr = {get() = 0x1310650} source_position = 0x7fffffffc6e0 destination_position = 0x7fffffffc726 source_orientation = 0x7fffffffc727 destination_orientation = 0xbcab10 (gdb) frame 6

6 0x000000000061bea8 in reactphysics3d::RigidBody::addCollisionShape (this=0x1310650, collisionShape=0x12f3120, transform=..., mass=1) at /home/projects/reactphysics3d/src/body/RigidBody.cpp:309

309 recomputeMassInformation(); (gdb) info locals proxyShape = 0x1318670 aabb = {mMinCoordinates = {x = -0.100000001, y = -0.0250000004, z = -0.0900000036}, mMaxCoordinates = {x = 0.100000001, y = 0.0250000004, z = 0.109999999}} (gdb) frame 5

5 0x000000000061c854 in reactphysics3d::RigidBody::recomputeMassInformation (this=0x1310650) at /home/projects/reactphysics3d/src/body/RigidBody.cpp:534

534 mInertiaTensorLocalInverse = inertiaTensorLocal.getInverse(); (gdb) info locals inertiaTensorLocal = {mRows = {{x = 0.00354166701, y = 0, z = 0}, {x = 0, y = 0.00666666729, z = 0}, {x = 0, y = 0, z = 0.00354166701}}} __PRETTY_FUNCTION__ = "void reactphysics3d::RigidBody::recomputeMassInformation()" oldCenterOfMass = {x = 0, y = 0, z = 0.00999999978} (gdb) frame 4

4 0x0000000000650edf in reactphysics3d::Matrix3x3::getInverse (this=0x7fffffffc3a0) at /home/projects/reactphysics3d/src/mathematics/Matrix3x3.cpp:51

51 assert(std::abs(determinant) > MACHINE_EPSILON); (gdb) info locals determinant = 8.36227088e-08 __PRETTY_FUNCTION__ = "reactphysics3d::Matrix3x3 reactphysics3d::Matrix3x3::getInverse() const" invDeterminant = -nan(0x7fc3a0) tempMatrix = {mRows = {{x = -nan(0x7fc2e0), y = 4.59163468e-41, z = 8.98691521e-39}, {x = 0, y = 0, z = 0.00354166701}, {x = -nan(0x7fc360), y = 0.00354166701, z = -nan(0x7fc490)}}} (gdb)

DanielChappuis commented 5 years ago

Can you paste here your code that you use to create the rigid body and to add the collision shapes to it ? This code alone should allow me to reproduce the issue on my side.

aliasdevelopment commented 5 years ago

`const rp3d::Vector3 initPosition_internal = rp3d::Vector3( object_data->position[0], object_data->position[1], object_data->position[2] );

// Initial position and orientation of the rigid body     
rp3d::Quaternion initOrientation = rp3d::Quaternion::identity(); 
rp3d::Transform transform(initPosition_internal, initOrientation);

//fetch transform for object_data
const rp3d::Vector3& pos_transform = transform.getPosition();
const rp3d::Quaternion& orientation_transform = transform.getOrientation();

const rp3d::Vector3 box_extend( extend[0]*0.5f, extend[1]*0.5f, extend[2]*0.5f ); //0.5f seince extend is half_width

std::unique_ptr< rp3d::BoxShape > shape = std::make_unique< rp3d::BoxShape >( box_extend );
rp3d::decimal shape_mass = rp3d::decimal( mass );
rp3d::Transform shape_transform = rp3d::Transform::identity();

std::unique_ptr< rp3d::RigidBody > body( world->createRigidBody( transform ) );

body->addCollisionShape( shape.get(), shape_transform, shape_mass );`
DanielChappuis commented 5 years ago

Thanks but I also need to following values to be able to debug it:

aliasdevelopment commented 5 years ago

From the gdb output, the values are:

initPosition_internal = {x = 0, y = 0, z = 0.00999999978} box_extend = {x = 0.100000001, y = 0.0250000004, z = 0.100000001}, since the input for extend was (0.2f, 0.05f, 0.2f) shape_mass = 1

DanielChappuis commented 5 years ago

The issue has been fixed in the commit 6ef177329b003d5eca4e44a8e688f70ca6b72162 in the master branch.

Can you try on your side if the issue is now fixed ?

aliasdevelopment commented 5 years ago

Sure. Hope I will manage to test it this weekend, plus the other issue we talked about.

DanielChappuis commented 5 years ago

Have you been able to test this ?

aliasdevelopment commented 5 years ago

The commit does not produce the assert anymore, and my scene works as expected. Had the scene where the issue was present, did a update to 6ef177329b and the issue disappeared.

DanielChappuis commented 5 years ago

Thanks a lot for the feedback and for reporting the issue.