diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 23ec2cf3dee66..d5f8df693e1f8 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -312,8 +312,10 @@ impl AddAsset for App { let mut app = self .world .non_send_resource_mut::(); - app.add_asset::() - .init_resource::>(); + app.get_mut(|app| { + app.add_asset::() + .init_resource::>(); + }); } self } @@ -335,7 +337,9 @@ impl AddAsset for App { let mut app = self .world .non_send_resource_mut::(); - app.init_asset_loader::(); + app.get_mut(|app| { + app.init_asset_loader::(); + }); } self } @@ -357,13 +361,15 @@ macro_rules! load_internal_asset { let mut debug_app = $app .world .non_send_resource_mut::<$crate::debug_asset_server::DebugAssetApp>(); - $crate::debug_asset_server::register_handle_with_loader( - $loader, - &mut debug_app, - $handle, - file!(), - $path_str, - ); + debug_app.get_mut(|mut debug_app| { + $crate::debug_asset_server::register_handle_with_loader( + $loader, + &mut debug_app, + $handle, + file!(), + $path_str, + ); + }); } let mut assets = $app.world.resource_mut::<$crate::Assets<_>>(); assets.set_untracked($handle, ($loader)(include_str!($path_str))); diff --git a/crates/bevy_asset/src/debug_asset_server.rs b/crates/bevy_asset/src/debug_asset_server.rs index b7e3c71c85c89..f37fc6b6b939b 100644 --- a/crates/bevy_asset/src/debug_asset_server.rs +++ b/crates/bevy_asset/src/debug_asset_server.rs @@ -77,31 +77,35 @@ impl Plugin for DebugAssetServerPlugin { } fn run_debug_asset_app(mut debug_asset_app: NonSendMut) { - debug_asset_app.0.update(); + debug_asset_app.get_mut(|debug_asset_app| { + debug_asset_app.0.update(); + }); } pub(crate) fn sync_debug_assets( mut debug_asset_app: NonSendMut, mut assets: ResMut>, ) { - let world = &mut debug_asset_app.0.world; - let mut state = SystemState::<( - Res>>, - Res>, - Res>, - )>::new(world); - let (changed_shaders, handle_map, debug_assets) = state.get_mut(world); - for changed in changed_shaders.iter_current_update_events() { - let debug_handle = match changed { - AssetEvent::Created { handle } | AssetEvent::Modified { handle } => handle, - AssetEvent::Removed { .. } => continue, - }; - if let Some(handle) = handle_map.handles.get(debug_handle) { - if let Some(debug_asset) = debug_assets.get(debug_handle) { - assets.set_untracked(handle, debug_asset.clone()); + debug_asset_app.get_mut(|debug_asset_app| { + let world = &mut debug_asset_app.0.world; + let mut state = SystemState::<( + Res>>, + Res>, + Res>, + )>::new(world); + let (changed_shaders, handle_map, debug_assets) = state.get_mut(world); + for changed in changed_shaders.iter_current_update_events() { + let debug_handle = match changed { + AssetEvent::Created { handle } | AssetEvent::Modified { handle } => handle, + AssetEvent::Removed { .. } => continue, + }; + if let Some(handle) = handle_map.handles.get(debug_handle) { + if let Some(debug_asset) = debug_assets.get(debug_handle) { + assets.set_untracked(handle, debug_asset.clone()); + } } } - } + }); } /// Uses the return type of the given loader to register the given handle with the appropriate type