Update getBodiesUnsafe() to return a slice of size getMaxBodies()#25
Open
r0ckHopper wants to merge 3 commits into
Open
Update getBodiesUnsafe() to return a slice of size getMaxBodies()#25r0ckHopper wants to merge 3 commits into
r0ckHopper wants to merge 3 commits into
Conversation
getBodiesUnsafe() returned ptr[0..getNumBodies()] but its values can go upto 1024 (getMaxBodies) After destroying bodies, the active count shrinks but remaining bodies stay at the same slots, causing out-of-bounds exceptions. The underlying Jolt array also uses max_bodies, so slicing to getMaxBodies() is safe.
Same issue as addressed in commit 77a907d getBodiesMutUnsafe() returned ptr[0..getNumBodies()] but its values can go upto 1024 (getMaxBodies) After destroying bodies, the active count shrinks but remaining bodies stay at the same slots, causing out-of-bounds exceptions. The underlying Jolt array also uses max_bodies, so slicing to getMaxBodies() is safe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently getBodiesUnsafe() returns a slice of size getNumBodies() but getBodiesUnsafe() actually returns a pointer to slice of size max_bodies.
The issue comes when you delete bodies from the middle and try to access bodies of higher index
getBodiesUnsafe does not reorganize the elements before giving a slice so you can get an out of bounds error
example of the issue is:
let bodies be
[b0, b1, b2]
if you delete b1 jolt physics updates bodies to
[b0, invalid, b2]
but if you call getBodiesUnsafe you only get
[b0, invalid]
so if you do tryGetBody( all_bodies, b2) then it will look for b2 at index 2 which is out of bounds