[WIP] Fix RID get_ptr_by_index access to freed objects #49501
Closed
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.
RID_Alloc get_ptr_by_index was allowing access to objects that had previously been freed, causing crashes in the BVH.
This PR changes the function to iterate by allocation id rather than index, and provides protection against access to freed allocations.
Fixes #44973
Notes
validator_chunks
index used should bep_index
oridx
, I'm just guessing by reverse engineering the existing code.Update
This version is changed to iterate through the list by allocation ID rather than
index
.. it doesn't matter the order for the BVH, and I suspect theindex
is semi random anyway, and iterating byalloc_id
is more efficient and simpler.While we could just check for nullptr and access up to
max_alloc
sequentially, it is inefficient if there are a lot of invalid allocations in the list, because of the spinlock .. so I'm trying a single function to move an iterator on to the next validalloc_id
.index
if desired, it isn't hugely different.used_list
, like if there are 512 members in the scenario minimum chunk size, it will iterate through all 512, even if only 1 is active.