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.
This PR implements a more general solution to the cleanup of layer Instance and Device proxies when the native handle is destroyed.
We need to erase the proxy from our map of known proxies before the native object is destroyed. This is because we need to dereference the native handle to get the dispatch key we use in our map, and we need to remove before calling the driver to avoid a race between dropping the old proxy and a new native object being allocated with the same handle in a different thread.
We need to delete the proxy after the native object is destroyed because it is possible for layers using callbacks to get those callbacks during the driver deletion call. No public layer needs this today, so this is not currently a functional bug, but it's a good futureproofing change.
The new design removes the proxy from our map on "Proxy::destroy" but moves ownership to the caller, so we now modify the map before the driver call and also keep the proxy alive until the layer function returns.