Skip to content
New issue

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

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

Already on GitHub? # to your account

Hit an assert in DynamicsWorld::integrateRigidBodiesVelocities #53

Closed
andreasdr opened this issue May 26, 2018 · 11 comments
Closed

Hit an assert in DynamicsWorld::integrateRigidBodiesVelocities #53

andreasdr opened this issue May 26, 2018 · 11 comments
Assignees
Labels

Comments

@andreasdr
Copy link

Hi,

I am hitting an assert when moving a dynamic rigid body into a static rigid body(also into a collision body).

Assertion failed: (mSplitLinearVelocities[indexBody] == Vector3(0, 0, 0)), function integrateRigidBodiesVelocities, file ext/reactphysics3d/src/engine/DynamicsWorld.cpp, line 297.

The game crashes then. Also when disabling asserts.

The backtrace looks like:

(gdb) bt
#0  0x00000000005c0030 in reactphysics3d::CollisionBody::updateProxyShapeInBroadPhase ()
#1  0x00000000005bfe1d in reactphysics3d::CollisionBody::updateBroadPhaseState ()
#2  0x00000000005a993c in reactphysics3d::DynamicsWorld::updateBodiesState ()
#3  0x00000000005a88c7 in reactphysics3d::DynamicsWorld::update ()
#4  0x00000000004709a4 in tdme::engine::physics::World::update ()
#5  0x00000000004172f6 in asw::ASWClientGameLogicThread::run ()
#6  0x00000000004f055a in tdme::os::threading::Thread::pThreadRun ()
#7  0x0000000801ef9bc5 in pthread_create () from /lib/libthr.so.3
#8  0x0000000000000000 in ?? ()

I will try to get a backtrace of debug build soon too.

Best regards
Andreas

@andreasdr andreasdr changed the title Hit an assert in DynamicsWorld Hit an assert in DynamicsWorld::integrateRigidBodiesVelocities May 26, 2018
@andreasdr
Copy link
Author

Hi

Backtrace with debug build looks like:

(gdb) bt
#0  0x000000000050846a in reactphysics3d::Vector3::operator= (this=0x83a3704f8, vector=@0x7fffdfbfa750) at Vector3.h:360
#1  0x00000000009e7bfa in reactphysics3d::DynamicsWorld::integrateRigidBodiesVelocities (this=0x8062b0000) at ext/reactphysics3d/src/engine/DynamicsWorld.cpp:301
#2  0x00000000009e7278 in reactphysics3d::DynamicsWorld::update (this=0x8062b0000, timeStep=0.0160000008) at ext/reactphysics3d/src/engine/DynamicsWorld.cpp:132
#3  0x00000000004ebdbb in tdme::engine::physics::World::update (this=0x8062b0000, deltaTime=0.0160000008) at src/tdme/engine/physics/World.cpp:179

I need collision bodies for several game features.

Best regards
Andreas

@DanielChappuis
Copy link
Owner

Hello. It seems to happen in the call of the DynamicsWorld.update() method. Are you doing something special in your code before you call this method (between this call and the previous one) ? Like adding, removing bodies from the world ?

Also, where the assert is hit, can I ask you what is the value of the variables "indexBody" and "mSplitLinearVelocities.size()" ?

@DanielChappuis DanielChappuis self-assigned this May 28, 2018
@andreasdr
Copy link
Author

I will do today.

@andreasdr
Copy link
Author

I am adding a collision body in a frame and then just remove it after several frames(means after several world.update() calls). So nothing special at all. Meanwhile I do not add or remove bodies.

@andreasdr
Copy link
Author

I have added the following line to debug:

Console::println(to_string(mBodies.size()) + ":" + to_string(indexBody));

(mSplitLinearVelocities is a C++ Array, not a STL container or something)

Before the game crashes it prints:
573:6337680
573:571

@andreasdr
Copy link
Author

Oh overread that too fast.

Also, where the assert is hit, can I ask you what is the value of the variables "indexBody" and "mSplitLinearVelocities.size()" ?

I will check tomorrow. I have made changes to TDME2 that requires me to modify game logics too.

@andreasdr
Copy link
Author

Hi,

please see attached a patch that fixes the crash.

diff --git a/ext/reactphysics3d/src/engine/DynamicsWorld.cpp b/ext/reactphysics3d/src/engine/DynamicsWorld.cpp
index 91112d74..68eff2ab 100644
--- a/ext/reactphysics3d/src/engine/DynamicsWorld.cpp
+++ b/ext/reactphysics3d/src/engine/DynamicsWorld.cpp
@@ -746,13 +746,18 @@ void DynamicsWorld::computeIslands() {
                 // Check if the current contact manifold has already been added into an island
                 if (contactManifold->isAlreadyInIsland()) continue;
 
+                // Get the other body of the contact manifold
+                RigidBody* body1 = dynamic_cast<RigidBody*>(contactManifold->getBody1());
+                RigidBody* body2 = dynamic_cast<RigidBody*>(contactManifold->getBody2());
+
+                // if body1 or body2 is nullptr dynamic cast have failed due to beeing collision body
+                if (body1 == nullptr || body2 == nullptr) continue;
+
                 // Add the contact manifold into the island
                 mIslands[mNbIslands]->addContactManifold(contactManifold);
                 contactManifold->mIsAlreadyInIsland = true;
 
-                // Get the other body of the contact manifold
-                RigidBody* body1 = static_cast<RigidBody*>(contactManifold->getBody1());
-                RigidBody* body2 = static_cast<RigidBody*>(contactManifold->getBody2());
+                //
                 RigidBody* otherBody = (body1->getId() == bodyToVisit->getId()) ? body2 : body1;
 
                 // Check if the other body has already been added to the island
@@ -781,6 +786,10 @@ void DynamicsWorld::computeIslands() {
                 // Get the other body of the contact manifold
                 RigidBody* body1 = static_cast<RigidBody*>(joint->getBody1());
                 RigidBody* body2 = static_cast<RigidBody*>(joint->getBody2());
+

Best regards
Andreas

@DanielChappuis
Copy link
Owner

Yes thanks. I have also found how to solve it yesterday evening with this commit. I was just running some tests to see that this fix was OK. I think our patches are similar.

I have pushed my changes into the develop branch. Could you test if the issue is also resolved on your side with the develop branch ?

@andreasdr
Copy link
Author

Ok. Nice. Will test later today.

@andreasdr
Copy link
Author

Seems to be fixed. Thank you.

@DanielChappuis
Copy link
Owner

Ok Thanks. The fix is now merged in the master branch.

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

No branches or pull requests

2 participants