Skip to content

Conversation

@solidpixel
Copy link
Contributor

@solidpixel solidpixel commented Jul 28, 2025

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.

@solidpixel solidpixel merged commit f29eda0 into main Jul 28, 2025
6 checks passed
@solidpixel solidpixel deleted the defer_destroy branch July 28, 2025 10:11
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