Skip to content

Commit

Permalink
Fix deadlock in the texture/image loaders (#3314)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored Sep 6, 2023
1 parent ec671e7 commit 2338a85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
51 changes: 27 additions & 24 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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();

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)
})
Err(load::LoadError::NotSupported)
}

fn loaders(&self) -> load::Loaders {
crate::profile_function!();
self.read(|this| this.loaders.clone()) // TODO(emilk): something less slow
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/egui/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
Expand Down

0 comments on commit 2338a85

Please sign in to comment.