Skip to content

Commit

Permalink
gltf loader: do not use the taskpool for only one task
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Jan 6, 2022
1 parent 2d301ea commit 9620483
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,36 +247,36 @@ async fn load_gltf<'a, 'b>(
.collect();

// TODO: use the threaded impl on wasm once wasm thread pool doesn't deadlock on it
#[cfg(target_arch = "wasm32")]
for gltf_texture in gltf.textures() {
let (texture, label) =
load_texture(gltf_texture, &buffer_data, &linear_textures, &load_context).await?;
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
}

#[cfg(not(target_arch = "wasm32"))]
load_context
.task_pool()
.scope(|scope| {
gltf.textures().for_each(|gltf_texture| {
let linear_textures = &linear_textures;
let load_context: &LoadContext = load_context;
let buffer_data = &buffer_data;
scope.spawn(async move {
load_texture(gltf_texture, buffer_data, linear_textures, load_context).await
if gltf.textures().len() == 1 || cfg!(target_arch = "wasm32") {
for gltf_texture in gltf.textures() {
let (texture, label) =
load_texture(gltf_texture, &buffer_data, &linear_textures, &load_context).await?;
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
}
} else {
load_context
.task_pool()
.scope(|scope| {
gltf.textures().for_each(|gltf_texture| {
let linear_textures = &linear_textures;
let load_context: &LoadContext = load_context;
let buffer_data = &buffer_data;
scope.spawn(async move {
load_texture(gltf_texture, buffer_data, linear_textures, load_context).await
});
});
})
.into_iter()
.filter_map(|res| {
if let Err(err) = res.as_ref() {
warn!("Error loading glTF texture: {}", err);
}
res.ok()
})
.for_each(|(texture, label)| {
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
});
})
.into_iter()
.filter_map(|res| {
if let Err(err) = res.as_ref() {
warn!("Error loading glTF texture: {}", err);
}
res.ok()
})
.for_each(|(texture, label)| {
load_context.set_labeled_asset(&label, LoadedAsset::new(texture));
});
}

let mut scenes = vec![];
let mut named_scenes = HashMap::default();
Expand Down

0 comments on commit 9620483

Please sign in to comment.