Skip to content

Conversation

@DaZombieKiller
Copy link

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.AsPointer causes a GC-tracked ref to lose its GC-tracked status, meaning that if a compacting garbage collection happens to occur before the pointer is converted back into a ref T via Unsafe.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.

@smoogipoo smoogipoo merged commit fa2546a into ppy:master Jan 1, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants