bevy
bevy copied to clipboard
Return an error when adding the same asset label multiple times.
Objective
- Fixes #19026.
Solution
- Make the labeled assets in
LoadContextbe a&Mutex<HashMap>. - Make
LoadContexts for subassets reuse the same&Mutex<HashMap>. - Immediately-loaded nested assets will naturally get a separate
Mutex<HashMap>, so their subassets will be managed separately.
Testing
- Added tests to show the various cases working.
@alice-i-cecile Not really. The problem is that we need to be able to differentiate between immediate nested asset loads and their subassets, from "root asset" subassets. This was the thing I missed in #15481, and not something that's easy to fix without gross hacks. This solution has the advantage that as soon as you add a duplicate subasset, you'll get the feedback.
I don't think we need to worry much about the Mutex. It's got quite a small critical section, and likely has very low contention (people are probably not adding many subassets from many threads), plus asset loading in general is IO-bound.