[3.8.1] box2d engine crashes when you deactive or destroy a node

Since CC 3.8 the box2d engine seems different.
I tried the new box2d-wasm, but I got the same problem.

    start() {
        let collider = this.getComponent(Collider2D);
        if (collider) {
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
        }
    }

    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        this.node.destroy(); // Crash
        this.node.active = false; // Crash
    }

at b2Body.SetActive (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\node_modules\@cocos\box2d\build\box2d\box2d.umd.js:7194:16)

at b2RigidBody2D.setActive (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:214566:22)

at b2RigidBody2D.onDisable (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:214408:16)

at RigidBody2D.onDisable (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:307317:24)

at eval (eval at tryCatchFunctor_EDITOR (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js), <anonymous>:4:10)

at ComponentScheduler.eval (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:48483:17)

at NodeActivator._deactivateNodeRecursively (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:51345:48)

at NodeActivator.activateNode (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:51195:18)

at Node.set active [as active] (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:54480:50)

at Node.destroy (C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:55537:25)

This happened to me. I just set a variable when collided and in the update method I check if its collided and if so destroy it

export class Obstacle extends Component {

    wasCollided: boolean = false;

    start() {
        this.node.getComponent(Collider2D).on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
    }

    update(deltaTime: number) {
        if (this.wasCollided) {
          this.node.destroy();
        }
    }

    onBeginContact(selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
        this.wasCollided = true;
    }
}


Yes, I did the same thing but I added the destoy in the lateUpdate function instead the update method. I don’t know if it’s a better place.

it might be. there’s no one right way in coding