DanielChappuis / reactphysics3d

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

Assertion error #26

Closed rweichler closed 6 years ago

rweichler commented 8 years ago

I'm not sure if this is because I'm using the library wrong, or if this is a bug. I managed to reproduce it with this code:

#include "reactphysics3d.h"

using namespace rp3d;

int main(int argc, char *argv[])
{
    DynamicsWorld *world = new DynamicsWorld(Vector3(0, -9.81, 0));
    // floor
    {
        BoxShape *shape = new BoxShape(Vector3(10, 1, 10));
        RigidBody *body = world->createRigidBody(Transform(Vector3(0, 0, 0), Quaternion(0, 0, 0, 1)));
        body->setType(STATIC);
        body->addCollisionShape(shape, Transform(Vector3(0, 0, 0), Quaternion(0, 0, 0, 1)), 90);
    }
    // box
    {
        BoxShape *shape = new BoxShape(Vector3(2, 2, 2));
        RigidBody *body = world->createRigidBody(Transform(Vector3(0, 10, 0), Quaternion(0, 0, 0, 1)));
        body->setType(DYNAMIC);
        body->addCollisionShape(shape, Transform(Vector3(0, 10, 0), Quaternion(0, 0, 0, 1)), 90);
    }
    while(true) {
        world->update(1.0f/60.0f);
    }
    return 0;
}

And the error:

Assertion failed: (wDotv > 0.0), function computePenetrationDepthAndContactPoints, file deps/reactphysics3d/collision/narrowphase/EPA/EPAAlgorithm.cpp, line 391.
Abort trap: 6

You can't see it in the command line, but in my game It errors the instant the box collides with the floor.

I think it's because I add the 2x2x2 box's shape to the body at (0, 10, 0) instead of (0, 0, 0) as it probably wants. Because if I put (0, 0, 0) for the position in addCollisionShape, it works as expected.

Also, if you don't do that and instead set the 2x2x2 box's size to 1x1x1, it stops crashing and works as expected.

Edit:

Also, another bug: If you try to update the dynamics world when it has no bodies, it crashes, presumably because it wants always to have bodies in it.

Thanks.

DanielChappuis commented 8 years ago

Thanks a lot for reporting this and thanks for your code. Can I ask you to try the same code but using the current "develop" branch (instead of master) ? I have improved the robustness of the collision detection recently. Also let me know if it still crashes with no bodies in the physics world.

Best Regards.

DanielChappuis commented 7 years ago

Fix both bugs at https://github.com/DanielChappuis/reactphysics3d/issues/26

xendian commented 7 years ago

I am getting the same assertion in EPAAlgorithm.cpp. Where can we get the fix?

DanielChappuis commented 7 years ago

I am currently working on improving the robustness of collision detection to fix this bug. I will let you know when this issue is fixed.

DanielChappuis commented 6 years ago

The version v0.7.0 of ReactPhysics3D has been released. This issue has been fixed in this release. Thanks a lot for reporting this.