Skip to content

Commit

Permalink
Primitives: fixed cleanup by setting "alive" flag after Body creation
Browse files Browse the repository at this point in the history
- I was getting strange behaviour and crashes on exit, because bodies
  were still being referenced by the World. The "alive" flag for Circle, Rect
  and Polygon was never set, so destroy() wasn't getting called in the
  destructor.
  • Loading branch information
totalgee committed Aug 29, 2013
1 parent 170ea0e commit 3ad7955
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ofxBox2dCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void ofxBox2dCircle::setup(b2World * b2dworld, float x, float y, float radius) {

body = b2dworld->CreateBody(&bodyDef);
body->CreateFixture(&fixture);

alive = true; // Need this, so the Body gets cleaned up in destructor
}
void ofxBox2dCircle::setup(b2World * b2dworld, ofVec2f &pts, float radius) {
setup(b2dworld, pts.x, pts.y, radius);
Expand Down
2 changes: 2 additions & 0 deletions src/ofxBox2dPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ void ofxBox2dPolygon::create(b2World * b2dworld) {

// update the area and centroid
updateShape();

alive = true; // Need this, so the Body gets cleaned up in destructor
}

//------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion src/ofxBox2dRect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void ofxBox2dRect::setup(b2World * b2dworld, float x, float y, float w, float h)

// update the rectShape
getRectangleShape();


alive = true; // Need this, so the Body gets cleaned up in destructor
}

//------------------------------------------------
Expand Down

0 comments on commit 3ad7955

Please sign in to comment.