Support destroy physicsMaterial (#2481)

* feat: support destroy physicsMaterial
This commit is contained in:
luzhuang
2025-01-02 11:33:59 +08:00
committed by GitHub
parent 01deebc80f
commit 4e659c8a5b
2 changed files with 10 additions and 2 deletions

View File

@@ -97,9 +97,9 @@ export class PhysicsMaterial {
}
/**
* @internal
* Destroy the material when the material is no be used by any shape.
*/
_destroy() {
destroy() {
!this._destroyed && this._nativeMaterial.destroy();
this._destroyed = true;
}

View File

@@ -486,4 +486,12 @@ describe("PhysicsMaterial", () => {
engine.sceneManager.activeScene.physics._update(1);
expect(formatValue(boxEntity2.transform.position.z)).eq(0.57139);
});
it("destroy", () => {
const physicsMaterial = new PhysicsMaterial();
physicsMaterial.destroy();
expect(() => {
physicsMaterial.bounciness = 1;
}).toThrowError();
});
});