Skip to content

Commit

Permalink
remove gltf loader async changes
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Aug 19, 2024
1 parent c491767 commit 33c8e2c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
5 changes: 5 additions & 0 deletions crates/bevy_asset/src/server/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ impl AssetInfos {
}

pub(crate) fn process_asset_fail(&mut self, failed_id: UntypedAssetId, error: AssetLoadError) {
// Check whether the handle has been dropped since the asset was loaded.
if !self.infos.contains_key(&failed_id) {
return;
}

let (dependants_waiting_on_load, dependants_waiting_on_rec_load) = {
let info = self
.get_mut(failed_id)
Expand Down
1 change: 0 additions & 1 deletion crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ base64 = "0.22.0"
percent-encoding = "2.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
futures = "0.3"
smallvec = "1.11"

[lints]
Expand Down
37 changes: 20 additions & 17 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ use bevy_render::{
};
use bevy_scene::Scene;
#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::IoTaskPool;
use bevy_transform::components::Transform;
use bevy_utils::tracing::{error, info_span, warn};
use bevy_utils::{HashMap, HashSet};
use futures::future::join_all;
use gltf::image::Source;
use gltf::{
accessor::Iter,
Expand Down Expand Up @@ -389,22 +389,25 @@ async fn load_gltf<'a, 'b, 'c>(
}
} else {
#[cfg(not(target_arch = "wasm32"))]
let futures = gltf.textures().map(|gltf_texture| {
let parent_path = load_context.path().parent().unwrap();
let linear_textures = &linear_textures;
let buffer_data = &buffer_data;
load_image(
gltf_texture,
buffer_data,
linear_textures,
parent_path,
loader.supported_compressed_formats,
settings.load_materials,
)
});

join_all(futures)
.await
IoTaskPool::get()
.scope(|scope| {
gltf.textures().for_each(|gltf_texture| {
let parent_path = load_context.path().parent().unwrap();
let linear_textures = &linear_textures;
let buffer_data = &buffer_data;
scope.spawn(async move {
load_image(
gltf_texture,
buffer_data,
linear_textures,
parent_path,
loader.supported_compressed_formats,
settings.load_materials,
)
.await
});
});
})
.into_iter()
.for_each(|result| match result {
Ok(image) => {
Expand Down

0 comments on commit 33c8e2c

Please sign in to comment.