void cpConstraintFree(cpConstraint *constraint) { if(constraint){ cpConstraintDestroy(constraint); cpfree(constraint); } }
Body::~Body(){ if(body){ //clean up all constraints constraintsToRemove.clear(); cpBodyEachConstraint(body, &constraintRemoveQuery, (void*)this); for(auto c: constraintsToRemove){ ((Constraint*)cpConstraintGetUserData(c))->constraint = nullptr; cpSpaceRemoveConstraint(cpConstraintGetSpace(c), c); cpConstraintDestroy(c); } //remove body cpSpaceRemoveBody(cpBodyGetSpace(body), body); cpBodyFree(body); body = nullptr; } }