LayaAir icon indicating copy to clipboard operation
LayaAir copied to clipboard

box2d的物理碰撞体销毁有时候会出现残留问题

Open lzsong opened this issue 4 years ago • 1 comments

跟了一下源码,在ColliderBase的_onDestroy里边去销毁的时候会

                if (this.fixture.GetBody() == this.rigidBody.body) {
                    this.rigidBody.body.DestroyFixture(this.fixture);
                }

可是其中的this.rigidBody.body在RigidBody的_onDisable中已经调用了this._body = null; 也就是说当先调用RigidBody的_onDisable后 然后再去销毁对象会造成DestroyFixture不会被调用

image image

lzsong avatar Apr 21 '20 07:04 lzsong

不会有问题,b2World::DestroyBody() 时,会自动删除所有相关的形状和关节。

KylinLove avatar Apr 21 '20 11:04 KylinLove