diff --git a/player/src/lib.rs b/player/src/lib.rs index 47799ef17..cb3ec5a07 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -136,6 +136,7 @@ impl GlobalPlay for wgc::hub::Global { } } self.command_encoder_finish::(encoder, &wgt::CommandBufferDescriptor { todo: 0 }) + .unwrap() } fn process( diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 423b965bd..b650f639b 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -26,6 +26,7 @@ use crate::{ }; use hal::command::CommandBuffer as _; +use thiserror::Error; use std::thread::ThreadId; @@ -141,12 +142,18 @@ impl BasePass { } } +#[derive(Clone, Debug, Error)] +pub enum CommandEncoderFinishError { + #[error("command buffer must be recording")] + NotRecording, +} + impl Global { pub fn command_encoder_finish( &self, encoder_id: id::CommandEncoderId, _desc: &wgt::CommandBufferDescriptor, - ) -> id::CommandBufferId { + ) -> Result { span!(_guard, INFO, "CommandEncoder::finish"); let hub = B::hub(self); @@ -155,7 +162,9 @@ impl Global { //TODO: actually close the last recorded command buffer let (mut comb_guard, _) = hub.command_buffers.write(&mut token); let comb = &mut comb_guard[encoder_id]; - assert!(comb.is_recording, "Command buffer must be recording"); + if !comb.is_recording { + return Err(CommandEncoderFinishError::NotRecording); + } comb.is_recording = false; // stop tracking the swapchain image, if used if let Some((ref sc_id, _)) = comb.used_swap_chain { @@ -166,7 +175,7 @@ impl Global { comb.trackers.views.remove(view_id.value); } log::trace!("Command buffer {:?} {:#?}", encoder_id, comb.trackers); - encoder_id + Ok(encoder_id) } pub fn command_encoder_push_debug_group(