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 fb5f1ef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
10 changes: 7 additions & 3 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 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 fb5f1ef

Please sign in to comment.