Fix potential crash when a descriptor set is destroyed but not unbound #8215
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.
When a descriptor set is destroyed, its
id<MTLBuffer>
s are still bound withinvertexDescriptorBindings
andfragmentDescriptorBindings
using__unsafe_unretained
pointers . This is a problem because those pointers will be garbage after the descriptor set is destroyed. At the next render pass, if a new descriptor set is not bound, we'll attempt to pass the garbage values tosetVertexBuffer:offset:atIndex
.Consider the following contrived repro case inside of a backend_test:
Some complications: the destruction of a descriptor set is delayed until the current command buffer completes AND the enclosing
@autoreleasepool
is drained. So, we need to insert aapi.finish(0)
and wrap every command around amDriver.execute
inside CommandStream.cpp.In production these conditions should be periodically met naturally, leading to spurious crashes.
Instead, by using a
__weak
reference, pointers will be automaticallynil
-ed when a descriptor set is destroyed. It's valid to passnil
tosetVertexBuffer:offset:atIndex
.BUGS=[374286912]