Skip to content

Commit

Permalink
fix debug asset server code
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Jun 29, 2022
1 parent 247f2b1 commit d366917
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
26 changes: 16 additions & 10 deletions crates/bevy_asset/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,10 @@ impl AddAsset for App {
let mut app = self
.world
.non_send_resource_mut::<crate::debug_asset_server::DebugAssetApp>();
app.add_asset::<T>()
.init_resource::<crate::debug_asset_server::HandleMap<T>>();
app.get_mut(|app| {
app.add_asset::<T>()
.init_resource::<crate::debug_asset_server::HandleMap<T>>();
});
}
self
}
Expand All @@ -335,7 +337,9 @@ impl AddAsset for App {
let mut app = self
.world
.non_send_resource_mut::<crate::debug_asset_server::DebugAssetApp>();
app.init_asset_loader::<T>();
app.get_mut(|app| {
app.init_asset_loader::<T>();
});
}
self
}
Expand All @@ -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)));
Expand Down
38 changes: 21 additions & 17 deletions crates/bevy_asset/src/debug_asset_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,35 @@ impl Plugin for DebugAssetServerPlugin {
}

fn run_debug_asset_app(mut debug_asset_app: NonSendMut<DebugAssetApp>) {
debug_asset_app.0.update();
debug_asset_app.get_mut(|debug_asset_app| {
debug_asset_app.0.update();
});
}

pub(crate) fn sync_debug_assets<T: Asset + Clone>(
mut debug_asset_app: NonSendMut<DebugAssetApp>,
mut assets: ResMut<Assets<T>>,
) {
let world = &mut debug_asset_app.0.world;
let mut state = SystemState::<(
Res<Events<AssetEvent<T>>>,
Res<HandleMap<T>>,
Res<Assets<T>>,
)>::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<Events<AssetEvent<T>>>,
Res<HandleMap<T>>,
Res<Assets<T>>,
)>::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
Expand Down

0 comments on commit d366917

Please sign in to comment.