Skip to content

Commit

Permalink
bugfix: premature GC after PhysicsScene.getBodies()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 3, 2024
1 parent 46cf513 commit 71968d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public BodyCreationSettings(ConstShape shape, RVec3Arg loc, QuatArg orient,
setVirtualAddress(bodySettingsVa, () -> free(bodySettingsVa));
}

/**
* Instantiate with the specified container and native object.
*
* @param container the containing object, or {@code null} if none
* @param bodySettingsVa the virtual address of the native object to assign
* (not zero)
*/
BodyCreationSettings(JoltPhysicsObject container, long bodySettingsVa) {
super(container, bodySettingsVa);
}

/**
* Instantiate settings with the specified native object assigned.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public BodyCreationSettings[] getBodies() {
BodyCreationSettings[] result = new BodyCreationSettings[numBodies];
for (int bodyIndex = 0; bodyIndex < numBodies; ++bodyIndex) {
long settingsVa = getBody(sceneVa, bodyIndex);
result[bodyIndex] = new BodyCreationSettings(settingsVa, false);
result[bodyIndex] = new BodyCreationSettings(this, settingsVa);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public BodyCreationSettings[] getBodies() {
BodyCreationSettings[] result = new BodyCreationSettings[numBodies];
for (int bodyIndex = 0; bodyIndex < numBodies; ++bodyIndex) {
long settingsVa = PhysicsScene.getBody(sceneVa, bodyIndex);
result[bodyIndex] = new BodyCreationSettings(settingsVa, false);
result[bodyIndex] = new BodyCreationSettings(this, settingsVa);
}

return result;
Expand Down

0 comments on commit 71968d4

Please sign in to comment.