Skip to content

Commit c30db18

Browse files
Fix memory leak on mesh collider destroy (#5106)
* 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 <59932779+mvaligursky@users.noreply.github.com> * Remove Ammo tests * Remove Ammo tests --------- Co-authored-by: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com>
1 parent ddbddaf commit c30db18

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/framework/components/collision/system.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class CollisionSystemImpl {
8383
component._compoundParent.entity.rigidbody.activate();
8484
}
8585

86-
Ammo.destroy(data.shape);
87-
data.shape = null;
86+
this.destroyShape(data);
8887
}
8988

9089
data.shape = this.createPhysicalShape(component.entity, data);
@@ -156,6 +155,13 @@ class CollisionSystemImpl {
156155
}
157156
}
158157

158+
destroyShape(data) {
159+
if (data.shape) {
160+
Ammo.destroy(data.shape);
161+
data.shape = null;
162+
}
163+
}
164+
159165
beforeRemove(entity, component) {
160166
if (component.data.shape) {
161167
if (component._compoundParent && !component._compoundParent.entity._destroying) {
@@ -167,8 +173,7 @@ class CollisionSystemImpl {
167173

168174
component._compoundParent = null;
169175

170-
Ammo.destroy(component.data.shape);
171-
component.data.shape = null;
176+
this.destroyShape(component.data);
172177
}
173178
}
174179

@@ -514,11 +519,6 @@ class CollisionMeshSystemImpl extends CollisionSystemImpl {
514519
Ammo.destroy(data.shape);
515520
data.shape = null;
516521
}
517-
518-
remove(entity, data) {
519-
this.destroyShape(data);
520-
super.remove(entity, data);
521-
}
522522
}
523523

524524
// Compound Collision System

0 commit comments

Comments
 (0)