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

Don't crash if a texture is destroyed before queue submission #5028

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions wgpu-core/src/command/memory_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::{
FastHashMap,
};

use super::{clear::clear_texture, BakedCommands, DestroyedBufferError, DestroyedTextureError};
use super::{
clear::clear_texture, BakedCommands, ClearError, DestroyedBufferError, DestroyedTextureError,
};

/// Surface that was discarded by `StoreOp::Discard` of a preceding renderpass.
/// Any read access to this surface needs to be preceded by a texture initialization.
Expand Down Expand Up @@ -301,15 +303,26 @@ impl<A: HalApi> BakedCommands<A> {

// TODO: Could we attempt some range collapsing here?
for range in ranges.drain(..) {
clear_texture(
let clear_result = clear_texture(
&texture_use.texture,
range,
&mut self.encoder,
&mut device_tracker.textures,
&device.alignments,
device.zero_buffer.as_ref().unwrap(),
)
.unwrap();
);

// A Texture can be destroyed between the command recording
// and now, this is out of our control so we have to handle
// it gracefully.
if let Err(ClearError::InvalidTexture(id)) = clear_result {
return Err(DestroyedTextureError(id));
}

// Other errors are unexpected.
if let Err(error) = clear_result {
panic!("{error}");
}
}
}

Expand Down