diff --git a/core/src/image.rs b/core/src/image.rs index b92fdb0d..267bb0ee 100644 --- a/core/src/image.rs +++ b/core/src/image.rs @@ -192,10 +192,12 @@ impl From<&Handle> for Handle { impl std::fmt::Debug for Handle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Path(_, path) => write!(f, "Path({path:?})"), - Self::Bytes(_, _) => write!(f, "Bytes(...)"), - Self::Rgba { width, height, .. } => { - write!(f, "Pixels({width} * {height})") + Self::Path(id, path) => write!(f, "Path({id:?}, {path:?})"), + Self::Bytes(id, _) => write!(f, "Bytes({id:?}, ...)"), + Self::Rgba { + id, width, height, .. + } => { + write!(f, "Pixels({id:?}, {width} * {height})") } } } diff --git a/wgpu/src/image/raster.rs b/wgpu/src/image/raster.rs index 0cccad06..5e333546 100644 --- a/wgpu/src/image/raster.rs +++ b/wgpu/src/image/raster.rs @@ -100,17 +100,21 @@ impl Cache { let hits = &self.hits; self.map.retain(|k, memory| { + // Retain active allocations + if let Memory::Device { allocation, .. } = memory + && allocation + .as_ref() + .is_some_and(|allocation| allocation.strong_count() > 0) + { + return true; + } + let retain = hits.contains(k); if !retain && let Memory::Device { - entry, - bind_group, - allocation: memory, + entry, bind_group, .. } = memory - && memory - .as_ref() - .is_none_or(|memory| memory.strong_count() == 0) { if let Some(bind_group) = bind_group.take() { on_drop(bind_group);