Skip to content

Commit

Permalink
feat: support destroy physicsMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
luzhuang committed Dec 27, 2024
1 parent 7d3c49e commit ca062bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/physics/PhysicsMaterial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/src/core/physics/PhysicsMaterial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit ca062bf

Please sign in to comment.