Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaN quaternion assert, master #79

Closed
aliasdevelopment opened this issue Jan 7, 2019 · 22 comments
Closed

NaN quaternion assert, master #79

aliasdevelopment opened this issue Jan 7, 2019 · 22 comments
Assignees
Labels

Comments

@aliasdevelopment
Copy link

aliasdevelopment commented Jan 7, 2019

Hi Daniel

I am trying a game scene which works using v0.7.0, but when I swap to the latest master I get the following assert.

The assert originates from a NaN lenght of the quaternion.

(gdb) frame 4
#4 0x000000000063f22c in reactphysics3d::Quaternion::getUnit (this=0x1462184) at /src/mathematics/Quaternion.h:266
266 assert (lengthQuaternion > MACHINE_EPSILON);
(gdb) info locals
lengthQuaternion = -nan(0x400000)
PRETTY_FUNCTION = "reactphysics3d::Quaternion reactphysics3d::Quaternion::getUnit() const"

#5 0x000000000063ce05 in reactphysics3d::DynamicsWorld::updateBodiesState (this=0x993820) at /src/engine/DynamicsWorld.cpp:222
222 bodies[b]->mTransform.setOrientation(mConstrainedOrientations[index].getUnit());
(gdb) info locals
index = 2
b = 0
bodies = 0x1427e90
islandIndex = 0

@DanielChappuis
Copy link
Owner

Hello,

Thanks a lot for reporting this issue.

Since you can reproduce the issue on your side, can I ask you to try to find the commit between v0.7.0 and master that seems to break something ? It would help me a lot.
Maybe try with a commit in the middle between v0.7.0 and master to begin with. I suspect the commits done in September 11 and 12 2018 to be responsible for this bug.

@DanielChappuis DanielChappuis self-assigned this Jan 8, 2019
@aliasdevelopment
Copy link
Author

It is not 100% reproducible, but after some tries the code will assert. I will try to track down the commit

@aliasdevelopment
Copy link
Author

aliasdevelopment commented Jan 19, 2019

The issue seems to be related to changes done in 45f86ea. The image below show the pile of approx. 200 objects which can produce this issue.

From v0.7.0 I get:

reactphysics3d/src/collision/ContactPointInfo.h:82: reactphysics3d::ContactPointInfo::ContactPointInfo(const reactphysics3d::Vector3&, reactphysics3d::decimal, const reactphysics3d::Vector3&, const reactphysics3d::Vector3&): Assertion `contactNormal.lengthSquare() > decimal(0.8)' failed.

From 45f86ea ("Fix issue with ConvexMeshShape and BoxShape falling through ConcaveMeshShape and HeightFieldShape", 2018-07-01) I get:

reactphysics3d/src/mathematics/Quaternion.h:266: reactphysics3d::Quaternion reactphysics3d::Quaternion::getUnit() const: Assertion `lengthQuaternion > MACHINE_EPSILON' failed.

pile

@DanielChappuis
Copy link
Owner

So if I understand correctly, you also have an assert with the 0.7.0 branch.

reactphysics3d/src/collision/ContactPointInfo.h:82: reactphysics3d::ContactPointInfo::ContactPointInfo(const reactphysics3d::Vector3&, reactphysics3d::decimal, const reactphysics3d::Vector3&, const reactphysics3d::Vector3&): Assertion `contactNormal.lengthSquare() > decimal(0.8)' failed.

Can I ask you to post the whole stacktrace for this assert with the 0.7.0 branch ?

@aliasdevelopment
Copy link
Author

Yes. When backtracking I found that v0.7.0 asserts in ContactPointInfo and from 45f86ea i got the quaternion assert.

@aliasdevelopment
Copy link
Author

aliasdevelopment commented Jan 19, 2019

Based on v0.7.0

(gdb) frame 11
#11 0x000000000043e19b in general::react::step (this=0x7445e0,
time_step=@0x7fffffffcd88: 0.01666666753590107)
at general/physics/react.hpp:266
266 world->update( time_step );
(gdb) info locals
No locals.
(gdb) frame 10
#10 0x00000000006128cb in reactphysics3d::DynamicsWorld::update (this=0x744690, timeStep=0.0166666675)
at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:126
126 mCollisionDetection.computeCollisionDetection();
(gdb) info locals
No locals.
(gdb) frame 9
#9 0x00000000005fe454 in reactphysics3d::CollisionDetection::computeCollisionDetection (this=0x744b48)
at /home/projects/reactphysics3d/src/collision/CollisionDetection.cpp:83
83 computeNarrowPhase();
(gdb) info local
No locals.
(gdb) frame 8
#8 0x00000000005fed52 in reactphysics3d::CollisionDetection::computeNarrowPhase (this=0x744b48)
at /home/projects/reactphysics3d/src/collision/CollisionDetection.cpp:275
275 if (narrowPhaseAlgorithm->testCollision(currentNarrowPhaseInfo, true, mMemoryManager.getSingleFrameAllocator())) {
(gdb) info local
lastCollisionFrameInfo = 0xb61a80
shape1Type = reactphysics3d::CollisionShapeType::CONVEX_POLYHEDRON
shape2Type = reactphysics3d::CollisionShapeType::CONVEX_POLYHEDRON
narrowPhaseAlgorithm = 0x744b88
narrowPhaseInfoToDelete = 0xc2a990
currentNarrowPhaseInfo = 0xc2a928
(gdb) frame 7
#7 0x0000000000623b17 in reactphysics3d::ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision (
this=0x744b88, narrowPhaseInfo=0xc2a928, reportContacts=true, memoryAllocator=...)
at /home/projects/reactphysics3d/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp:53
53 bool isColliding = satAlgorithm.testCollisionConvexPolyhedronVsConvexPolyhedron(narrowPhaseInfo, reportContacts);
(gdb) info local
satAlgorithm = {static SAME_SEPARATING_AXIS_BIAS = 0.00100000005, mMemoryAllocator = @0x744ab8}
lastFrameCollisionInfo = 0xb61a80
isColliding = false
(gdb) frame 6
#6 0x0000000000633697 in reactphysics3d::SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron
(this=0x7fffffffcc58, narrowPhaseInfo=0xc2a928, reportContacts=true)
at /home/projects/reactphysics3d/src/collision/narrowphase/SAT/SATAlgorithm.cpp:788
788 narrowPhaseInfo->addContactPoint(normalWorld, minPenetrationDepth,
(gdb) info local
closestPointPolyhedron1Edge = {x = -0.0130107105, y = -0.103171058, z = 0.100990966}
closestPointPolyhedron2Edge = {x = -0.0130106881, y = -0.107500002, z = 0.107500002}
closestPointPolyhedron1EdgeLocalSpace = {x = 0.107499972, y = -0.107499972, z = -0.0293074735}
normalWorld = {x = 0, y = 0, z = 0}
PRETTY_FUNCTION = "bool reactphysics3d::SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(reactphysics3d::NarrowPhaseInfo*, bool) const"
polyhedron1 = 0x983110
polyhedron2 = 0xb14520
polyhedron1ToPolyhedron2 = {mPosition = {x = 0.0150943063, y = -0.170910105, z = 0.237346947},
mOrientation = {x = 0.392655522, y = 0.57227838, z = 0.439421892, w = 0.570287108}}
polyhedron2ToPolyhedron1 = {mPosition = {x = 0.236108676, y = -0.17268081, z = -0.0143416375},
mOrientation = {x = -0.392655522, y = -0.57227838, z = -0.439421892, w = 0.570287108}}
minPenetrationDepth = 3.40282347e+38
minFaceIndex = 0
isMinPenetrationFaceNormal = false
isMinPenetrationFaceNormalPolyhedron1 = false
minSeparatingEdge1Index = 10
minSeparatingEdge2Index = 12
separatingEdge1A = {x = 0.123497009, y = -0.0956342667, z = 0.106003329}
separatingEdge1B = {x = -0.0910318941, y = -0.107478723, z = 0.0981261432}
separatingEdge2A = {x = -0.107500002, y = -0.107500002, z = 0.107500002}
separatingEdge2B = {x = 0.107500002, y = -0.107500002, z = 0.107500002}
minEdgeVsEdgeSeparatingAxisPolyhedron2Space = {x = 0, y = 0, z = 0}
isTemporalCoherenceValid = true
lastFrameCollisionInfo = 0xb61a80
(gdb) frame 5
#5 0x0000000000604f14 in reactphysics3d::NarrowPhaseInfo::addContactPoint (this=0xc2a928,
contactNormal=..., penDepth=3.40282347e+38, localPt1=..., localPt2=...)
at /home/projects/reactphysics3d/src/collision/NarrowPhaseInfo.cpp:74
74 ContactPointInfo(contactNormal, penDepth, localPt1, localPt2);
(gdb) info local
PRETTY_FUNCTION = "void reactphysics3d::NarrowPhaseInfo::addContactPoint(const reactphysics3d::Vector3&, reactphysics3d::decimal, const reactphysics3d::Vector3&, const reactphysics3d::Vector3&)"
allocator = @0x744ab8: {
_vptr.MemoryAllocator = 0x682ef0 <vtable for reactphysics3d::SingleFrameAllocator+16>}
contactPointInfo = 0x408590 <_start>
(gdb) frame 4
#4 0x0000000000605132 in reactphysics3d::ContactPointInfo::ContactPointInfo (this=0xc43390,
contactNormal=..., penDepth=3.40282347e+38, localPt1=..., localPt2=...)
at /home/projects/reactphysics3d/src/collision/ContactPointInfo.h:82
82 assert(contactNormal.lengthSquare() > decimal(0.8));
(gdb) info local
PRETTY_FUNCTION = "reactphysics3d::ContactPointInfo::ContactPointInfo(const reactphysics3d::Vector3&, reactphysics3d::decimal, const reactphysics3d::Vector3&, const reactphysics3d::Vector3&)"
(gdb)

@DanielChappuis
Copy link
Owner

Thanks a lot. I think I will need to reproduce it on my side to find the issue.

Are you able to share the code that you use to create the bodies and collision shapes of your scene ?

@DanielChappuis
Copy link
Owner

I have pushed some changes in the commit 6bcb586 in the master branch.

Can you try again and let me know if the issue still occurs in master ? If so, does the same assert raises or another one ?

@aliasdevelopment
Copy link
Author

Tried 6bcb586 and still get the assert:

(gdb) frame 4
#4 0x0000000000617ace in reactphysics3d::Quaternion::getUnit (this=0xccbe0c) at /home/projects/reactphysics3d/src/mathematics/Quaternion.h:280
280 assert (lengthQuaternion > MACHINE_EPSILON);
(gdb) frame 5
#5 0x000000000061569b in reactphysics3d::DynamicsWorld::updateBodiesState (this=0x749820) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:222
222 bodies[b]->mTransform.setOrientation(mConstrainedOrientations[index].getUnit());
(gdb) frame 6
#6 0x0000000000615167 in reactphysics3d::DynamicsWorld::update (this=0x749820, timeStep=0.0166666675) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:144
144 updateBodiesState();

@aliasdevelopment
Copy link
Author

aliasdevelopment commented Jan 25, 2019

Tried another experiment:

// Return the length of the quaternion (inline)
inline decimal Quaternion::length() const {

const double& x_local = x;
const double& y_local = y;
const double& z_local = z;
const double& w_local = w;

const double l_local = std::sqrt(x_local*x_local + y_local*y_local + z_local*z_local + w_local*w_local);

assert( l_local <= 1.1f );
assert( x_local <= 1.1f );
assert( y_local <= 1.1f );
assert( z_local <= 1.1f );
assert( w_local <= 1.1f );

return l_local;

}

I needed the assert limit to be 1.1 in order to pass the length calculation. Seems as if quats calculation precision errors are accumulated in the quat somewhere. You may need to normalize the quats if these are accumulated. Unsure if this is the case.

By use of the 1.1 I got the following:

(gdb) frame 4
#4 0x000000000042b81d in reactphysics3d::Quaternion::length (this=0xcd88f4) at /home/projects/reactphysics3d/src/mathematics/Quaternion.h:238
238 assert( l_local <= 1.1f );
(gdb) info locals
x_local = @0x7fffffffcc58: nan(0x8000000000000)
y_local = @0x7fffffffcc60: nan(0x8000000000000)
z_local = @0x7fffffffcc68: nan(0x8000000000000)
w_local = @0x7fffffffcc70: nan(0x8000000000000)
l_local = nan(0x8000000000000)
PRETTY_FUNCTION = "reactphysics3d::decimal reactphysics3d::Quaternion::length() const"
(gdb)

Note that I instrumented all input pos and quat from my code to reactphysics which did not assert

@DanielChappuis
Copy link
Owner

I do renormalize the orientation quaternions each frame. It's hard to find the issue without being able to reproduce it on my side.

I have created the issue79 branch with some new asserts. Can you please try this branch ? I expect that another assert is raised. If so, can you post the whole stack trace (with the state of the variables) ?

Thanks for your help.

@aliasdevelopment
Copy link
Author

Sorry for the late response. Tried you issue79 branch and got the following:

(gdb) f 4
#4  0x000000000061553d in reactphysics3d::DynamicsWorld::integrateRigidBodiesPositions (this=0x749820) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:195
195	            assert(mConstrainedOrientations[indexArray].length() > decimal(0.7));
(gdb) info locals
newLinVelocity = {x = -nan(0x400000), y = -nan(0x400000), z = -nan(0x400000)}
indexArray = 15
newAngVelocity = {x = -nan(0x400000), y = -nan(0x400000), z = -nan(0x400000)}
currentPosition = @0x79c96c: {x = 0.314421415, y = 0.197511688, z = -5.39995146}
currentOrientation = @0x79c928: {x = 0.10593237, y = 0.536624551, z = -0.600152314, w = -0.583634734}
b = 0
bodies = 0xc978e0
i = 0
__PRETTY_FUNCTION__ = "void reactphysics3d::DynamicsWorld::integrateRigidBodiesPositions()"
(gdb) f 5 
#5  0x0000000000615167 in reactphysics3d::DynamicsWorld::update (this=0x749820, timeStep=0.0166666675) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:138
138	    integrateRigidBodiesPositions();
(gdb) info locals
No locals.
(gdb)

@DanielChappuis
Copy link
Owner

I have added more asserts in the issue79 branch. Can you pull the changes and report again the stack trace and variables status when an assert is hit ?

I need to know where in the code the linear or angular velocity starts to become NaN.

@aliasdevelopment
Copy link
Author

(gdb) f 4
#4 0x0000000000630175 in reactphysics3d::ContactSolver::solve (this=0x74cab0) at /home/projects/reactphysics3d/src/engine/ContactSolver.cpp:614
614 assert(!isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].x) && !isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].y) && !isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].z));
(gdb) info locals
v1Split = @0xcd0b4c: {x = nan(0x400000), y = nan(0x400000), z = nan(0x400000)}
w2Split = @0xcd189c: {x = 0, y = 0, z = 0}
lambdaTempSplit = 0
w1Split = @0xcd13f8: {x = inf, y = inf, z = -nan(0x400000)}
v2Split = @0xcd0ff0: {x = 0, y = 0, z = 0}
deltaVSplit = {x = -nan(0x400000), y = -nan(0x400000), z = -nan(0x400000)}
JvSplit = -nan(0x400000)
deltaLambdaSplit = nan(0x400000)
linearImpulse = {x = nan(0x400000), y = nan(0x400000), z = nan(0x400000)}
deltaV = {x = -0.0895478651, y = 0.0383616015, z = 0.0337879248}
Jv = 0.0317073315
beta = 0.200000003
deltaVDotN = 0.0317073315
biasPenetrationDepth = 0
b = 0
linearImpulse = {x = 0.0705409572, y = -0.000146056482, z = 0.0841069296}
i = 0
sumPenetrationImpulse = 0.112858638
w2 = @0xcd29f4: {x = 0.136935592, y = 0.0356784686, z = 0.189613909}
deltaV = {x = 0.912132263, y = 0.0611389577, z = -0.978149772}
angularImpulseBody1 = {x = -0.00798619352, y = -0.00622871518, z = 0.00220135041}
linearImpulseBody2 = {x = -0.0045615281, y = 0.0269872826, z = 0.0598118529}
v1 = @0xcd1ca4: {x = -0.0231256187, y = -0.00464438694, z = -0.0024779262}
angularImpulseBody2 = {x = -0.00317788147, y = 0.00344028836, z = -0.00179462798}
w1 = @0xcd2550: {x = 0.155888617, y = -0.589179397, z = 0.730922222}
v2 = @0xcd2148: {x = -0.0373808146, y = 0.00165242597, z = 0.0207242705}
Jv = -0.186003059
deltaLambda = 0.00501549616
frictionLimit = 0.528464317
c = 148
deltaLambda = -0.109772608
lambdaTemp = 0.222631246
contactPointIndex = 230
PRETTY_FUNCTION = "void reactphysics3d::ContactSolver::solve()"
(gdb) f 5
#5 0x0000000000616723 in reactphysics3d::DynamicsWorld::solveContactsAndConstraints (this=0x74c820) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:389
389 mContactSolver.solve();
(gdb) info locals
i = 0
(gdb) f 6
#6 0x0000000000615309 in reactphysics3d::DynamicsWorld::update (this=0x74c820, timeStep=0.0166666675) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:135
135 solveContactsAndConstraints();
(gdb) infor locals
Undefined command: "infor". Try "help".
(gdb) info locals
No locals.
(gdb) f 7
#7 0x000000000042fe33 in general::react::step (this=0x74c770, time_step=@0x7fffffffcd98: 0.01666666753590107) at /home/projects/test/applications/general/physics/react.hpp:299
299 world->update( time_step );

@DanielChappuis
Copy link
Owner

Thanks a lot for your help. I have added more asserts in the issue79 branch.

Can you pull the branch and try again ?

@aliasdevelopment
Copy link
Author

The issue originates from invalid penetrationDepth which result in infinit biasPenetrationDepth which result in infinit deltaLambdaSplit which result in infinit linearImpulse which result in the previous assert comment

(gdb) f 4
#4 0x000000000063074b in reactphysics3d::ContactSolver::solve (this=0x74cab0) at /home/projects/reactphysics3d/src/engine/ContactSolver.cpp:631
631 assert(!isnan(deltaLambdaSplit) && !isinf(deltaLambdaSplit));
(gdb) info locals
v1Split = @0xcd9e34: {x = 0, y = 0, z = 0}
JvSplit = 0
lambdaTempSplit = 0
w1Split = @0xcda704: {x = 0, y = 0, z = 0}
v2Split = @0xcda080: {x = 0, y = 0, z = 0}
deltaVSplit = {x = 0, y = 0, z = 0}
myNormal = {x = 0.710426629, y = -0.355548561, z = 0.607353985}
i1TimesR1CrossN = {x = 5.52619667e-07, y = 1.51970437e-06, z = 2.76309891e-07}
w2Split = @0xcda950: {x = 0, y = 0, z = 0}
deltaLambdaSplit = inf
mymTimeStep = 0.0166666675
massInverseBody1 = 0.142857149
linearImpulse = {x = inf, y = -inf, z = inf}
deltaV = {x = 0.0821360499, y = 0.0222194158, z = -0.0716024041}
Jv = 0.00696354732
beta = 0.200000003
penetrationDepth = 3.40282347e+38
restitutionBias = 0
deltaVDotN = 0.00696354732
biasPenetrationDepth = -inf
b = -inf
linearImpulse = {x = -0.0084846979, y = 0.00424635271, z = -0.00725369062}
i = 0
sumPenetrationImpulse = 0.29013136
w2 = @0xcdbaf0: {x = -0.929118752, y = 0.0858408064, z = -1.88186836}
deltaV = {x = 7.09244919, y = -0.000515746535, z = 12.1726418}
angularImpulseBody1 = {x = -0.000990078901, y = -2.34759021, z = 0.00336194178}
linearImpulseBody2 = {x = 0.66028446, y = 1.6787586e-05, z = 0.206173733}
v1 = @0xcdafd4: {x = 0.00364194647, y = -0.0015590426, z = -0.0116455862}
angularImpulseBody2 = {x = -4.77838324e-10, y = 3.4443492e-05, z = -1.27423549e-09}
w1 = @0xcdb8a4: {x = -0.0948167667, y = -0.0977335423, z = -0.0606228933}
v2 = @0xcdb220: {x = 0.203246191, y = -0.193829656, z = -0.147219107}
Jv = -0.00106446724
deltaLambda = 3.4443492e-05
frictionLimit = 0.342782468
c = 286
deltaLambda = -0.0119431019
lambdaTemp = 0.302074462
contactPointIndex = 433
PRETTY_FUNCTION = "void reactphysics3d::ContactSolver::solve()"
(gdb) q

My local changes looks like this:

diff --git a/src/engine/ContactSolver.cpp b/src/engine/ContactSolver.cpp
index e9b73e69..22eb81de 100644
--- a/src/engine/ContactSolver.cpp
+++ b/src/engine/ContactSolver.cpp
@@ -539,9 +539,12 @@ void ContactSolver::solve() {
             // Compute the bias "b" of the constraint
             decimal beta = mIsSplitImpulseActive ? BETA_SPLIT_IMPULSE : BETA;
             decimal biasPenetrationDepth = 0.0;
-            if (mContactPoints[contactPointIndex].penetrationDepth > SLOP) biasPenetrationDepth = -(beta/mTimeStep) *
-                    max(0.0f, float(mContactPoints[contactPointIndex].penetrationDepth - SLOP));
-            decimal b = biasPenetrationDepth + mContactPoints[contactPointIndex].restitutionBias;
+            decimal penetrationDepth = mContactPoints[contactPointIndex].penetrationDepth;
+            if (penetrationDepth > SLOP) biasPenetrationDepth = -(beta/mTimeStep) *
+                    max(0.0f, float(penetrationDepth - SLOP));
+            
+            decimal restitutionBias = mContactPoints[contactPointIndex].restitutionBias;
+            decimal b = biasPenetrationDepth + restitutionBias;
 
             // Compute the Lagrange multiplier lambda
             if (mIsSplitImpulseActive) {
@@ -613,19 +616,29 @@ void ContactSolver::solve() {
                             deltaLambdaSplit, decimal(0.0));
                 deltaLambdaSplit = mContactPoints[contactPointIndex].penetrationSplitImpulse - lambdaTempSplit;
 
-                Vector3 linearImpulse(mContactPoints[contactPointIndex].normal.x * deltaLambdaSplit,
-                                      mContactPoints[contactPointIndex].normal.y * deltaLambdaSplit,
-                                      mContactPoints[contactPointIndex].normal.z * deltaLambdaSplit);
+                Vector3 myNormal = mContactPoints[contactPointIndex].normal;
+                
+                Vector3 i1TimesR1CrossN = mContactPoints[contactPointIndex].i1TimesR1CrossN;
+                
+                decimal mymTimeStep = mTimeStep;
+                
+                decimal massInverseBody1 = mContactConstraints[c].massInverseBody1;
+                
+                Vector3 linearImpulse(myNormal.x * deltaLambdaSplit,
+                                      myNormal.y * deltaLambdaSplit,
+                                      myNormal.z * deltaLambdaSplit);
+                
+                assert(!isnan(deltaLambdaSplit) && !isinf(deltaLambdaSplit));
 
                 // Update the velocities of the body 1 by applying the impulse P
-                mSplitLinearVelocities[mContactConstraints[c].indexBody1].x -= mContactConstraints[c].massInverseBody1 * linearImpulse.x;
-                mSplitLinearVelocities[mContactConstraints[c].indexBody1].y -= mContactConstraints[c].massInverseBody1 * linearImpulse.y;
-                mSplitLinearVelocities[mContactConstraints[c].indexBody1].z -= mContactConstraints[c].massInverseBody1 * linearImpulse.z;
+                mSplitLinearVelocities[mContactConstraints[c].indexBody1].x -= massInverseBody1 * linearImpulse.x;
+                mSplitLinearVelocities[mContactConstraints[c].indexBody1].y -= massInverseBody1 * linearImpulse.y;
+                mSplitLinearVelocities[mContactConstraints[c].indexBody1].z -= massInverseBody1 * linearImpulse.z;
                 assert(!isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].x) && !isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].y) && !isnan(mSplitLinearVelocities[mContactConstraints[c].indexBody1].z));
 
-                mSplitAngularVelocities[mContactConstraints[c].indexBody1].x -= mContactPoints[contactPointIndex].i1TimesR1CrossN.x * deltaLambdaSplit;
-                mSplitAngularVelocities[mContactConstraints[c].indexBody1].y -= mContactPoints[contactPointIndex].i1TimesR1CrossN.y * deltaLambdaSplit;
-                mSplitAngularVelocities[mContactConstraints[c].indexBody1].z -= mContactPoints[contactPointIndex].i1TimesR1CrossN.z * deltaLambdaSplit;
+                mSplitAngularVelocities[mContactConstraints[c].indexBody1].x -= i1TimesR1CrossN.x * deltaLambdaSplit;
+                mSplitAngularVelocities[mContactConstraints[c].indexBody1].y -= i1TimesR1CrossN.y * deltaLambdaSplit;
+                mSplitAngularVelocities[mContactConstraints[c].indexBody1].z -= i1TimesR1CrossN.z * deltaLambdaSplit;
                 assert(!isnan(mSplitAngularVelocities[mContactConstraints[c].indexBody1].x) && !isnan(mSplitAngularVelocities[mContactConstraints[c].indexBody1].y) && !isnan(mSplitAngularVelocities[mContactConstraints[c].indexBody1].z));
 
                 // Update the velocities of the body 1 by applying the impulse P

@DanielChappuis
Copy link
Owner

Thanks. Yes it seems the penetrationDepth is the maximum floating number (DECIMAL_LARGEST constant in the code). I have added more asserts in the issue79 branch to track in which collision method this penetration depth is set.

Could you pull the branch and try it ?

@aliasdevelopment
Copy link
Author

(gdb) f 4
#4 0x00000000006380f4 in reactphysics3d::SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron (this=0x7fffffffcc88, narrowPhaseInfo=0xc42758, reportContacts=true)
at /home/projects/reactphysics3d/src/collision/narrowphase/SAT/SATAlgorithm.cpp:615
615 assert(penetrationDepth < DECIMAL_LARGEST);
(gdb) info locals
closestPointPolyhedron1Edge = {x = -0.250821233, y = 0.138337284, z = 0}
vec2 = {x = -nan(0x7fcbf4), y = 4.59163468e-41, z = -0.292066544}
edge1LengthSquare = 1.74267495e-38
t2 = 4.59163468e-41
closestPointPolyhedron2Edge = {x = -0.250821233, y = 0.138337284, z = -0.0761631206}
vec1 = {x = 0.912965536, y = 0.284940839, z = -0.0761631206}
edge2LengthSquare = 0
t1 = -nan(0x7fcc00)
separatingAxisPolyhedron2Space = {x = 0, y = 0, z = 0}
polyhedron1Centroid = {x = -0.17728278, y = -0.256656528, z = -0.0523000434}
penetrationDepth = 3.40282347e+38
edge2 = @0xbb8610: {vertexIndex = 4, twinEdgeIndex = 15, faceIndex = 3, nextEdgeIndex = 5}
edge1B = {x = -0.113892227, y = -0.118512616, z = 0.0552483201}
edge2A = {x = -0.107500002, y = -0.107500002, z = -0.107500002}
edge2Direction = {x = 0, y = 0, z = 0.215000004}
edge1 = @0xbba8d0: {vertexIndex = 6, twinEdgeIndex = 17, faceIndex = 1, nextEdgeIndex = 1}
edge1A = {x = -0.103510804, y = -0.12344037, z = -0.159444362}
edge1Direction = {x = -0.0103814229, y = 0.0049277544, z = 0.214692682}
edge2B = {x = -0.107500002, y = -0.107500002, z = 0.107500002}
PRETTY_FUNCTION = "bool reactphysics3d::SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(reactphysics3d::NarrowPhaseInfo*, bool) const"
polyhedron1 = 0xbb8940
polyhedron2 = 0xbb8090
polyhedron1ToPolyhedron2 = {mPosition = {x = -0.17728278, y = -0.256656528, z = -0.0523000434}, mOrientation = {x = -0.0151362177, y = -0.0220366158, z = 0.157955512, w = 0.98708427}}
polyhedron2ToPolyhedron1 = {mPosition = {x = 0.250494003, y = 0.186640918, z = 0.0495475866}, mOrientation = {x = 0.0151362177, y = 0.0220366158, z = -0.157955512, w = 0.98708427}}
minPenetrationDepth = 3.40282347e+38
minFaceIndex = 0
isMinPenetrationFaceNormal = false
isMinPenetrationFaceNormalPolyhedron1 = false
minSeparatingEdge1Index = 0
minSeparatingEdge2Index = 0
separatingEdge1A = {x = 0, y = 0, z = 0}
separatingEdge1B = {x = 0, y = 0, z = 0}
separatingEdge2A = {x = 0, y = 0, z = 0}
separatingEdge2B = {x = 0, y = 0, z = 0}
isShape1Triangle = false
lastFrameCollisionInfo = 0xbdd758
faceIndex1 = 0
penetrationDepth1 = 0
faceIndex2 = 0
penetrationDepth2 = 0
(gdb) f 5
#5 0x0000000000625fc9 in reactphysics3d::ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision (this=0x74e8c8, narrowPhaseInfo=0xc42758, reportContacts=true, memoryAllocator=...)
at /home/projects/reactphysics3d/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp:53
53 bool isColliding = satAlgorithm.testCollisionConvexPolyhedronVsConvexPolyhedron(narrowPhaseInfo, reportContacts);
(gdb) info locals
satAlgorithm = {static SEPARATING_AXIS_RELATIVE_TOLERANCE = 1.00199997, static SEPARATING_AXIS_ABSOLUTE_TOLERANCE = 0.000500000024, mMemoryAllocator = @0x738c80}
lastFrameCollisionInfo = 0xbdd758
isColliding = false
(gdb) f 6
#6 0x0000000000601836 in reactphysics3d::CollisionDetection::computeNarrowPhase (this=0x74e888) at /home/projects/reactphysics3d/src/collision/CollisionDetection.cpp:275
275 if (narrowPhaseAlgorithm->testCollision(currentNarrowPhaseInfo, true, mMemoryManager.getSingleFrameAllocator())) {
(gdb) info locals
lastCollisionFrameInfo = 0xbdd758
shape1Type = reactphysics3d::CollisionShapeType::CONVEX_POLYHEDRON
shape2Type = reactphysics3d::CollisionShapeType::CONVEX_POLYHEDRON
narrowPhaseAlgorithm = 0x74e8c8
narrowPhaseInfoToDelete = 0xc427c0
currentNarrowPhaseInfo = 0xc42758
(gdb) f 7
#7 0x0000000000600f38 in reactphysics3d::CollisionDetection::computeCollisionDetection (this=0x74e888) at /home/projects/reactphysics3d/src/collision/CollisionDetection.cpp:83
83 computeNarrowPhase();
(gdb) info locals
No locals.
(gdb) f 8
#8 0x00000000006154cd in reactphysics3d::DynamicsWorld::update (this=0x74e820, timeStep=0.0166666675) at /home/projects/reactphysics3d/src/engine/DynamicsWorld.cpp:126
126 mCollisionDetection.computeCollisionDetection();
(gdb) info locals
No locals.
(gdb)

@DanielChappuis
Copy link
Owner

Thanks. I have pushed a fix in the issue79 branch.

Could you pull this fix and let me know if you still have an error ?

@DanielChappuis
Copy link
Owner

Hello. Have you been able to test the fix ?

@aliasdevelopment
Copy link
Author

Hi Daniel

Sorry for the late response.

I have tested 4ef6900 against f3ea557 ( head of issue79 branch )

4ef6900 asserted 13 out of 200 runs
f3ea557 asserted 0 out of 200 runs

Based of this, the issue is fixed

@DanielChappuis
Copy link
Owner

I have just merged the fix into the "master" branch.
Thanks a lot for reporting this issue and for helping me fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants