From be70c908e22b5e39445cfe12674c111ba5199fa9 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 14 Apr 2015 20:49:23 -0700 Subject: [PATCH 1/2] Also fix leaks from fixtures Same game as for bodies, just need to iterate over their list of fixtures. --- creature.pde | 2 ++ food.pde | 2 ++ projectile.pde | 2 ++ rocks.pde | 2 ++ tower.pde | 2 ++ 5 files changed, 10 insertions(+) diff --git a/creature.pde b/creature.pde index e40a12b..868fbea 100644 --- a/creature.pde +++ b/creature.pde @@ -610,6 +610,8 @@ class creature { // remove reference to creature body.setUserData(null); + for (Fixture f = body.getFixtureList(); f != null; f = f.getNext()) + f.setUserData(null); // Delete the body box2d.destroyBody(body); } diff --git a/food.pde b/food.pde index d4aebe8..5f97d2a 100644 --- a/food.pde +++ b/food.pde @@ -51,6 +51,8 @@ class food { // This function removes the particle from the box2d world void killBody() { the_food.setUserData(null); + for (Fixture f = the_food.getFixtureList(); f != null; f = f.getNext()) + f.setUserData(null); box2d.destroyBody(the_food); } diff --git a/projectile.pde b/projectile.pde index 0fbdfcb..b17c477 100644 --- a/projectile.pde +++ b/projectile.pde @@ -57,6 +57,8 @@ class projectile { void killBody() { if (the_projectile != null) { the_projectile.setUserData(null); + for (Fixture f = the_projectile.getFixtureList(); f != null; f = f.getNext()) + f.setUserData(null); box2d.destroyBody(the_projectile); } } diff --git a/rocks.pde b/rocks.pde index 4228623..e110b0b 100644 --- a/rocks.pde +++ b/rocks.pde @@ -36,6 +36,8 @@ class rock { // This function removes the particle from the box2d world void killBody() { the_rock.setUserData(null); + for (Fixture f = the_rock.getFixtureList(); f != null; f = f.getNext()) + f.setUserData(null); box2d.destroyBody(the_rock); } diff --git a/tower.pde b/tower.pde index bd5fc97..611f8ef 100644 --- a/tower.pde +++ b/tower.pde @@ -170,6 +170,8 @@ class tower { if (inTransit) { if (!wasInTransit) { tower_body.setUserData(null); + for (Fixture f = tower_body.getFixtureList(); f != null; f = f.getNext()) + f.setUserData(null); box2d.destroyBody(tower_body); } wasInTransit = true; From 2f6af8de1be00dfdd68737f7c1ffd0ac9ea07af2 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 14 Apr 2015 21:03:36 -0700 Subject: [PATCH 2/2] Update readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ec9daf..68d0de2 100644 --- a/README.md +++ b/README.md @@ -261,12 +261,16 @@ our objects. After a [long search][sway] for our memory leak, we have found that the fix for this is to remove the reference via `body.setUserData(null)` when the body is no longer needed (that is, -in `killBody()` for the respective object). Please ensure this is done -for any new body types added to EvolvedTD. See #203 for more -information. +in `killBody()` for the respective object). Box2D bodies also have +fixture lists, which similarly need their user data set to null. If we +ever add joints, they would need to be taken care of as well. Please +ensure this is done for any new body types added to EvolvedTD. See +[#203][] and [#205][] for more information. [lib]: https://github.com/processing/processing/wiki/How-to-Install-a-Contributed-Library [sway]: https://sway.com/3xv6q3uMP1SzS6OW +[#203]: https://github.com/tsoule88/evolvedTD/pull/203 +[#205]: https://github.com/tsoule88/evolvedTD/pull/205 # Data Collection