open-rmf / rmf_site

Experimental visualizer for dense buildings in RMF
32 stars 13 forks source link

Sanitize asset paths before passing them to the loader #223

Closed mxgrey closed 3 months ago

mxgrey commented 3 months ago

The bevy asset loader has a very unfortunate behavior of panicking if it receives an asset path with invalid syntax.

To prevent that I've changed the implementation of AssetSource from providing From<&AssetSource> for String to TryFrom<&AssetSource> for String, forcing us to verify that the asset source can be converted into an asset path with correct syntax before we pass it along to the bevy asset loader.

There are some cases where we just want to get any string out of the asset source and don't need it to have valid syntax, so for that I created an unsafe AssetSource method that simply does what the String conversion used to do. But this forces us to use unsafe and verify that we don't need valid syntax before using it.

To A/B test the panicking behavior, you can simply load up the demo world, select anything with a texture (e.g. wall or floor) and type one colon : anywhere in the asset source path. On the current main that will immediately make it panic. With this PR it should never panic; instead it will log an error to the console.