diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 92ac46d27d..2c5c9eaa14 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -35,7 +35,7 @@ impl CommandPool { if index < lowest_active_index { let cmd_buf = self.pending.swap_remove(i); log::trace!( - "recycling comb submitted in {} when {} is done", + "recycling comb submitted in {} when {} is lowest active", index, lowest_active_index, ); diff --git a/wgpu-core/src/device.rs b/wgpu-core/src/device.rs index c140641c6d..4ad66bdc2b 100644 --- a/wgpu-core/src/device.rs +++ b/wgpu-core/src/device.rs @@ -1546,11 +1546,12 @@ impl> Global { ref_count: device.life_guard.ref_count.clone(), }; - // The first entry in the active list should have the lowest index + // Find the pending entry with the lowest active index. If none can be found that means + // everything in the allocator can be cleaned up, so std::usize::MAX is correct. let lowest_active_index = device.pending.lock() - .active.get(0) - .map(|active| active.index) - .unwrap_or(0); + .active + .iter() + .fold(std::usize::MAX, |v, active| active.index.min(v)); let mut comb = device .com_allocator