From edc767fa66b37204f2935536d7e735b66f1c0cbe Mon Sep 17 00:00:00 2001 From: darkfi Date: Tue, 23 Dec 2025 19:08:42 -0300 Subject: [PATCH] app/gfx: remove option from GfxDrawMesh::compile() and just panic in the failure case. Any such error is an internal error. --- bin/app/src/gfx/anim.rs | 2 +- bin/app/src/gfx/mod.rs | 48 ++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/bin/app/src/gfx/anim.rs b/bin/app/src/gfx/anim.rs index 6ea1c0867..0be91429c 100644 --- a/bin/app/src/gfx/anim.rs +++ b/bin/app/src/gfx/anim.rs @@ -64,7 +64,7 @@ impl GfxSeqAnim { ) { assert!(frame_idx < self.frames.len()); let duration = std::time::Duration::from_millis(frame.duration as u64); - let dc = frame.dc.compile(textures, buffers, 0).unwrap(); + let dc = frame.dc.compile(textures, buffers, 0); self.frames[frame_idx] = Some(GfxFrame { duration, dc }); //t!("got frame {frame_idx}"); } diff --git a/bin/app/src/gfx/mod.rs b/bin/app/src/gfx/mod.rs index 161eab2f7..d701fa578 100644 --- a/bin/app/src/gfx/mod.rs +++ b/bin/app/src/gfx/mod.rs @@ -362,46 +362,46 @@ impl DrawMesh { textures: &HashMap, buffers: &HashMap, debug_str: &'static str, - ) -> Option { + ) -> GfxDrawMesh { let vertex_buffer_id = self.vertex_buffer.id; let index_buffer_id = self.index_buffer.id; let _buffers_keep_alive = [self.vertex_buffer, self.index_buffer]; let texture = match self.texture { - Some(gfx_texture) => Self::try_get_texture(textures, gfx_texture, debug_str), + Some(gfx_texture) => Some(Self::get_texture(textures, gfx_texture, debug_str)), None => None, }; - Some(GfxDrawMesh { - vertex_buffer: Self::try_get_buffer(buffers, vertex_buffer_id, debug_str)?, - index_buffer: Self::try_get_buffer(buffers, index_buffer_id, debug_str)?, + GfxDrawMesh { + vertex_buffer: Self::get_buffer(buffers, vertex_buffer_id, debug_str), + index_buffer: Self::get_buffer(buffers, index_buffer_id, debug_str), _buffers_keep_alive, texture, num_elements: self.num_elements, - }) + } } - fn try_get_texture( + fn get_texture( textures: &HashMap, gfx_texture: ManagedTexturePtr, debug_str: &'static str, - ) -> Option<(ManagedTexturePtr, miniquad::TextureId)> { + ) -> (ManagedTexturePtr, miniquad::TextureId) { let gfx_texture_id = gfx_texture.id; let Some(_mq_texture_id) = textures.get(&gfx_texture_id) else { panic!("Missing texture ID={gfx_texture_id} debug={debug_str}") }; - Some((gfx_texture, textures[&gfx_texture_id])) + (gfx_texture, textures[&gfx_texture_id]) } - fn try_get_buffer( + fn get_buffer( buffers: &HashMap, gfx_buffer_id: BufferId, debug_str: &'static str, - ) -> Option { + ) -> miniquad::BufferId { let Some(mq_buffer_id) = buffers.get(&gfx_buffer_id) else { panic!("Missing buffer ID={gfx_buffer_id} debug={debug_str}") }; - Some(*mq_buffer_id) + *mq_buffer_id } } @@ -459,19 +459,18 @@ impl DrawInstruction { textures: &HashMap, buffers: &HashMap, debug_str: &'static str, - ) -> Option { - let instr = match self { + ) -> GfxDrawInstruction { + match self { Self::SetScale(scale) => GfxDrawInstruction::SetScale(scale), Self::Move(off) => GfxDrawInstruction::Move(off), Self::SetPos(pos) => GfxDrawInstruction::SetPos(pos), Self::ApplyView(view) => GfxDrawInstruction::ApplyView(view), Self::Draw(mesh) => { - GfxDrawInstruction::Draw(mesh.compile(textures, buffers, debug_str)?) + GfxDrawInstruction::Draw(mesh.compile(textures, buffers, debug_str)) } Self::Animation(anim) => GfxDrawInstruction::Animation(anim), Self::EnableDebug => GfxDrawInstruction::EnableDebug, - }; - Some(instr) + } } } @@ -498,17 +497,17 @@ impl DrawCall { textures: &HashMap, buffers: &HashMap, timest: Timestamp, - ) -> Option { - Some(GfxDrawCall { + ) -> GfxDrawCall { + GfxDrawCall { instrs: self .instrs .into_iter() .map(|i| i.compile(textures, buffers, self.debug_str)) - .collect::>>()?, + .collect(), dcs: self.dcs, z_index: self.z_index, timest, - }) + } } } @@ -1244,12 +1243,7 @@ impl Stage { d!("Invoked method: replace_draw_calls({:?})", dcs); } for (key, val) in dcs { - let Some(val) = val.compile(&self.textures, &self.buffers, timest) else { - if DEBUG_TRAX { - get_trax().lock().put_stat(3); - } - panic!("fatal: replace_draw_calls({timest}, ...) failed with item ID={key}") - }; + let val = val.compile(&self.textures, &self.buffers, timest); //self.draw_calls.insert(key, val); match self.draw_calls.get_mut(&key) { Some(old_val) => {