Skip to content

Commit 85fd4f6

Browse files
author
Chris Sanders
committed
Fix potential memory leak on cache purge.
Signed-off-by: Chris Sanders <[email protected]>
1 parent d9ef930 commit 85fd4f6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/main/java/org/spout/physics/engine/DynamicsWorld.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,13 +603,17 @@ public boolean isTicking() {
603603
* Disperses the cache of bodies added/removed during the physics tick.
604604
*/
605605
public void disperseCache() {
606-
for (RigidBody body : mRigidBodiesToAddCache) {
607-
addRigidBody(body);
608-
}
606+
//Only add bodies that aren't being removed
607+
mRigidBodiesToAddCache.removeAll(mRigidBodiesToDeleteCache);
609608

610609
for (RigidBody body : mRigidBodiesToDeleteCache) {
611610
destroyRigidBody(body);
612611
}
612+
613+
for (RigidBody body : mRigidBodiesToAddCache) {
614+
addRigidBody(body);
615+
}
616+
613617
mRigidBodiesToAddCache.clear();
614618
mRigidBodiesToDeleteCache.clear();
615619
}

src/main/java/org/spout/physics/engine/linked/LinkedDynamicsWorld.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public LinkedDynamicsWorld(Vector3 gravity, LinkedWorldInfo info) {
6868
}
6969

7070
@Override
71-
protected void tick(float dt) {
72-
super.tick(dt);
71+
public void update() {
72+
super.update();
7373
clearLinkedBodies();
7474
}
7575

0 commit comments

Comments
 (0)