Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure SharedAssetDepot stays alive while lock is held #1050

Merged
merged 2 commits into from
Dec 23, 2024

Conversation

kring
Copy link
Member

@kring kring commented Dec 23, 2024

This is a PR into #1049 so merge that first.

This fixes a problem I noticed while looking at CesiumGS/cesium-unity#540. The SharedAssetDepot keeps itself alive until the last asset it manages becomes unreferenced. It does this by maintaining an IntrusivePointer to itself in some situations. The problem is that it can release this reference while the current thread also holds the mutex. This will result in the SharedAssetDepot being destroyed (just) before the mutex is released, which causes undefined behavior (an assert in debug builds, to start).

This PR adds a test to demonstrate the problem. It fixes it by using a helper class to hold a reference to the depot while the mutex is locked, so that the depot always outlives the mutex lock.

Base automatically changed from shared-asset-depot-not-inline to main December 23, 2024 14:45
@j9liu
Copy link
Contributor

j9liu commented Dec 23, 2024

Thanks @kring ! I think everything makes sense. Nothing jumps out at me so I'll go ahead and merge 😄

@j9liu j9liu merged commit 75c7744 into main Dec 23, 2024
22 checks passed
@j9liu j9liu deleted the asset-depot-destruction branch December 23, 2024 15:06
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