Skip to content

Commit

Permalink
Fix memory leak on mesh collider destroy (#5106)
Browse files Browse the repository at this point in the history
* Added `destroyShape` function to global system

* Use of `destroyShape`

* Fixed shape destruction on `recreatePhysicalShapes`

* Reverted extra line deleted

* Made shape null in `destroyShape`

* Added Ammo for testing modules requiring Ammo to work

* Added test for shape colliders destruction on collision component destroy

* Remove not relevant anymore comment

* Shortened shape destroying

Co-authored-by: Martin Valigursky <[email protected]>

* Remove Ammo tests

* Remove Ammo tests

---------

Co-authored-by: Martin Valigursky <[email protected]>
  • Loading branch information
MushAsterion and mvaligursky committed May 12, 2023
1 parent ddbddaf commit c30db18
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/framework/components/collision/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ class CollisionSystemImpl {
component._compoundParent.entity.rigidbody.activate();
}

Ammo.destroy(data.shape);
data.shape = null;
this.destroyShape(data);
}

data.shape = this.createPhysicalShape(component.entity, data);
Expand Down Expand Up @@ -156,6 +155,13 @@ class CollisionSystemImpl {
}
}

destroyShape(data) {
if (data.shape) {
Ammo.destroy(data.shape);
data.shape = null;
}
}

beforeRemove(entity, component) {
if (component.data.shape) {
if (component._compoundParent && !component._compoundParent.entity._destroying) {
Expand All @@ -167,8 +173,7 @@ class CollisionSystemImpl {

component._compoundParent = null;

Ammo.destroy(component.data.shape);
component.data.shape = null;
this.destroyShape(component.data);
}
}

Expand Down Expand Up @@ -514,11 +519,6 @@ class CollisionMeshSystemImpl extends CollisionSystemImpl {
Ammo.destroy(data.shape);
data.shape = null;
}

remove(entity, data) {
this.destroyShape(data);
super.remove(entity, data);
}
}

// Compound Collision System
Expand Down

0 comments on commit c30db18

Please sign in to comment.