wgpu-rs:`线程 'main' 在 'Texture[1] does not exist' 处恐慌`
wgpu-rs: `thread 'main' panicked at 'Texture[1] does not exist'`
我在 render
方法中创建了一个 wgpu::TextureView
,如下所示:
let mut encoder = self.device.create_command_encoder(...);
let texture_view = self
.surface
.get_current_frame()?
.output
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &texture_view,
...
}],
...
})
render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);
render_pass.draw_indexed(...);
self.queue.submit(std::iter::once(encoder.finish()));
但是当我 运行 程序时,它会崩溃:
thread 'main' panicked at 'Texture[1] does not exist', /home/doliphin/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.10.0/src/hub.rs:129:32
这可以通过在 TextureView
之后强制删除 SurfaceTexture
来解决。
let mut encoder = self.device.create_command_encoder(...);
let surface_texture = self.surface.get_current_frame()?.output; // SurfaceTexture
{
let texture_view = surface_texture
.texture
.create_view(&wgpu::TextureViewDescriptor::default()); // TextureView
let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &texture_view,
...
}],
...
})
render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);
render_pass.draw_indexed(...);
}
// drop(render_pass);
// drop(texture_view);
self.queue.submit(std::iter::once(encoder.finish()));
// drop(surface_texture)
// drop(encoder)
我在 render
方法中创建了一个 wgpu::TextureView
,如下所示:
let mut encoder = self.device.create_command_encoder(...);
let texture_view = self
.surface
.get_current_frame()?
.output
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &texture_view,
...
}],
...
})
render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);
render_pass.draw_indexed(...);
self.queue.submit(std::iter::once(encoder.finish()));
但是当我 运行 程序时,它会崩溃:
thread 'main' panicked at 'Texture[1] does not exist', /home/doliphin/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.10.0/src/hub.rs:129:32
这可以通过在 TextureView
之后强制删除 SurfaceTexture
来解决。
let mut encoder = self.device.create_command_encoder(...);
let surface_texture = self.surface.get_current_frame()?.output; // SurfaceTexture
{
let texture_view = surface_texture
.texture
.create_view(&wgpu::TextureViewDescriptor::default()); // TextureView
let mut render_pass = encoder.begin_render_pas(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &texture_view,
...
}],
...
})
render_pass.set_/* pipeline, bind_group, vertex_buffer, index_buffer */(...);
render_pass.draw_indexed(...);
}
// drop(render_pass);
// drop(texture_view);
self.queue.submit(std::iter::once(encoder.finish()));
// drop(surface_texture)
// drop(encoder)