Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when submitting two command buffers together that render to a surface #2844

Closed
HeroesGrave opened this issue Jul 3, 2022 · 1 comment · Fixed by #2843
Closed

Crash when submitting two command buffers together that render to a surface #2844

HeroesGrave opened this issue Jul 3, 2022 · 1 comment · Fixed by #2843

Comments

@HeroesGrave
Copy link
Contributor

Description
If you create 2 command encoders and create a render pass in each referring to a surface (possibly can even be different surfaces but I haven't checked), then submit the resulting command buffers together, the program crashes

Repro steps
Make the following change to the cube example

diff --git a/wgpu/examples/cube/main.rs b/wgpu/examples/cube/main.rs
index dadf81b0..00f4b144 100644
--- a/wgpu/examples/cube/main.rs
+++ b/wgpu/examples/cube/main.rs
@@ -392,8 +392,24 @@ impl framework::Example for Example {
                 rpass.draw_indexed(0..self.index_count as u32, 0, 0..1);
             }
         }
-
-        queue.submit(Some(encoder.finish()));
+        let mut encoder2 =
+            device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
+        {
+            let mut rpass = encoder2.begin_render_pass(&wgpu::RenderPassDescriptor {
+                label: None,
+                color_attachments: &[Some(wgpu::RenderPassColorAttachment {
+                    view,
+                    resolve_target: None,
+                    ops: wgpu::Operations {
+                        load: wgpu::LoadOp::Load,
+                        store: true,
+                    },
+                })],
+                depth_stencil_attachment: None,
+            });
+        }
+        
+        queue.submit([encoder.finish(), encoder2.finish()]);
 
         // If an error occurs, report it and panic.
         spawner.spawn_local(ErrorFuture {

Run the example (with RUST_BACKTRACE=1)

thread 'main' panicked at 'assertion failed: index < self.owned.len()', <removed>/wgpu/wgpu-core/src/track/mod.rs:355:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f2d93935ffba3ab9d7ccb5300771a2d29b4c8bf3/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/f2d93935ffba3ab9d7ccb5300771a2d29b4c8bf3/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/f2d93935ffba3ab9d7ccb5300771a2d29b4c8bf3/library/core/src/panicking.rs:48:5
   3: wgpu_core::track::ResourceMetadata<A>::debug_assert_in_bounds
             at <removed>/wgpu/wgpu-core/src/track/mod.rs:355:9
   4: wgpu_core::track::texture::TextureUsageScope<A>::debug_assert_in_bounds
             at <removed>/wgpu/wgpu-core/src/track/texture.rs:237:9
   5: wgpu_core::track::texture::TextureUsageScope<A>::merge_single
             at <removed>/wgpu/wgpu-core/src/track/texture.rs:360:9
   6: wgpu_core::device::queue::<impl wgpu_core::hub::Global<G>>::queue_submit
             at <removed>/wgpu/wgpu-core/src/device/queue.rs:850:37
   7: <wgpu::backend::direct::Context as wgpu::Context>::queue_submit
             at ./src/backend/direct.rs:2291:15
   8: wgpu::Queue::submit
             at ./src/lib.rs:3497:19
   9: <cube::Example as cube::framework::Example>::render
             at ./examples/cube/main.rs:412:9
  10: cube::framework::start::{{closure}}
             at ./examples/cube/../framework.rs:375:17

(end of the backtrace removed because it's not particularly relevant)

Extra materials
Probably due to this line replacing used_surface_textures without ensuring it has enough capacity?

used_surface_textures = track::TextureUsageScope::new();

Platform
Linux with wayland (sway)
AMD Radeon RX 6700 XT (Vulkan)

@cwfitzgerald
Copy link
Member

Oooo that's a scary one, thank god for debug asserts - will patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants