saharan / OimoPhysics

A cross-platform 3D physics engine
MIT License
863 stars 68 forks source link

removeShape (RigidBody.hx) - Error #51

Closed Snky closed 2 years ago

Snky commented 2 years ago
    public function removeShape(shape:Shape):Void {
        // first, remove the shape from the linked list so that it will be ignored
        M.list_remove(_shapeList, _shapeListLast, _prev, _next, shape);
        _numShapes--;
        shape._rigidBody = null;

        // then remove the shape from the world
        if (_world != null) {
            _world._removeShape(shape);
        }

        _shapeModified();
    }

Should shape._rigidBody = null go (after) before _shapeModified();? As _world.removeShape(shape); requires shape._rigidBody(NULL)._contactLinkList

Dev-MarkoF commented 2 years ago

It's a bug, which i mentioned years ago, when i needed scaling bodies at runtime, but it seems it did not get fixed. Just move the shape._rigidbody = null, below the if statement and there is no error. I didn't notice any unwated side effects, by doing so, it now works like i think it is intended.

saharan commented 2 years ago

Yes, you're right, the shape should firstly be removed from the world. Thank you for reporting, I'll fix it.

saharan commented 2 years ago

Fixed in Release 1.2.4