Fix deadlock in the texture/image loaders (#3314)

This commit is contained in:
Emil Ernerfeldt 2023-09-06 15:36:08 +02:00 committed by GitHub
parent ec671e754f
commit 2338a854f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 25 deletions

View File

@ -1980,16 +1980,15 @@ impl Context {
/// [not_supported]: crate::load::LoadError::NotSupported
/// [custom]: crate::load::LoadError::Custom
pub fn try_load_bytes(&self, uri: &str) -> load::BytesLoadResult {
self.read(|this| {
for loader in &this.loaders.bytes {
match loader.load(self, uri) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
let loaders = self.loaders();
for loader in &loaders.bytes {
match loader.load(self, uri) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
}
Err(load::LoadError::NotSupported)
})
Err(load::LoadError::NotSupported)
}
/// Try loading the image from the given uri using any available image loaders.
@ -2009,16 +2008,15 @@ impl Context {
/// [not_supported]: crate::load::LoadError::NotSupported
/// [custom]: crate::load::LoadError::Custom
pub fn try_load_image(&self, uri: &str, size_hint: load::SizeHint) -> load::ImageLoadResult {
self.read(|this| {
for loader in &this.loaders.image {
match loader.load(self, uri, size_hint) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
let loaders = self.loaders();
for loader in &loaders.image {
match loader.load(self, uri, size_hint) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
}
Err(load::LoadError::NotSupported)
})
Err(load::LoadError::NotSupported)
}
/// Try loading the texture from the given uri using any available texture loaders.
@ -2043,16 +2041,21 @@ impl Context {
texture_options: TextureOptions,
size_hint: load::SizeHint,
) -> load::TextureLoadResult {
self.read(|this| {
for loader in &this.loaders.texture {
match loader.load(self, uri, texture_options, size_hint) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
}
let loaders = self.loaders();
Err(load::LoadError::NotSupported)
})
for loader in &loaders.texture {
match loader.load(self, uri, texture_options, size_hint) {
Err(load::LoadError::NotSupported) => continue,
result => return result,
}
}
Err(load::LoadError::NotSupported)
}
fn loaders(&self) -> load::Loaders {
crate::profile_function!();
self.read(|this| this.loaders.clone()) // TODO(emilk): something less slow
}
}

View File

@ -396,6 +396,7 @@ impl TextureLoader for DefaultTextureLoader {
}
}
#[derive(Clone)]
pub(crate) struct Loaders {
pub include: Arc<DefaultBytesLoader>,
pub bytes: Vec<Arc<dyn BytesLoader + Send + Sync + 'static>>,