-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Return an error from Assets::insert
instead of panicking.
#20439
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
Conversation
aa8345e
to
891caa0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks clean, thanks for the fix!
Putting this in the milestone because it fixes Bevy reaching unreachable!
code in sensible user code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would have been nice to avoid unwraps when the handle is guaranteed to be a UUID. But I can't see a way to do that without adding a AssetUuid
type and changing a bunch of APIs, so seems out of scope for this PR.
Co-authored-by: Greeble <166992735+greeble-dev@users.noreply.github.com>
…ne#20439) # Objective - Inserting into a dropped AssetId would panic. There is no API to check if the asset ID is still valid, so you can't avoid this case. For a concrete example, imagine a user uses `Assets::reserve_handle` to get a handle, and then passes its AssetId into an async task. While the async task is running, the user drops the handle, which removes the entry from `Assets`. Later when the async task returns, it tries to insert the asset into that `AssetId`. This previously caused a panic. [Based on a true story](https://discord.com/channels/691052431525675048/749332104487108618/1402511976898498590). ## Solution - Make `Assets::insert` return an error when inserting into a dropped `AssetId`. ## Testing - Added a test specifically for this case. --------- Co-authored-by: Greeble <166992735+greeble-dev@users.noreply.github.com>
Objective
For a concrete example, imagine a user uses
Assets::reserve_handle
to get a handle, and then passes its AssetId into an async task. While the async task is running, the user drops the handle, which removes the entry fromAssets
. Later when the async task returns, it tries to insert the asset into thatAssetId
. This previously caused a panic. Based on a true story.Solution
Assets::insert
return an error when inserting into a droppedAssetId
.Testing