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 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;