Skip to content

Do I need to cleanup the old shape when using SetShape() on a body? #175

Discussion options

You must be logged in to vote

You would not call destroy. This is automatically handled inside Jolt due to it being a special Reference class, assuming you manage shape-creation and shape-settings correctly. If that Shape was not used elsewhere by another Reference, by the time you run jolt.destroy Jolt already destroyed it during SetShape and you are double-free-ing the memory.

const existingShape = body.GetShape();
body.SetShape(newShape);
 //do not call this jolt.destroy(existingShape);

However, it's likely I also created that shape too in an earlier call to SetShape()

SetShape does not create a new shape, it just assigns the pointer newShape to the body. This allows you to make a single shape, such as a giant Me…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@DennisSmolek
Comment options

@LeXXik
Comment options

@PhoenixIllusion
Comment options

@jrouwe
Comment options

@PhoenixIllusion
Comment options

Answer selected by DennisSmolek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants