Remove use of AsRef(AsPointer(ref source)) pattern #60
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.
The
Unsafe.AsRef<T>(Unsafe.AsPointer(ref source))pattern is almost always a bug, and is unfortunately present in a few places in the Veldrid codebase.Unsafe.AsPointercauses a GC-trackedrefto lose its GC-tracked status, meaning that if a compacting garbage collection happens to occur before the pointer is converted back into aref TviaUnsafe.AsRef<T>, the pointer will become stale because the GC was not able to update it to point at the new location of the data. This is known as a GC hole.In this PR I've removed all instances of the pattern and replaced them with equivalent GC-safe versions.