diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-03 20:43:44 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-03 20:48:01 +0200 |
| commit | 57a9ffc9d598838e136f187d7ab158e9b5c6e311 (patch) | |
| tree | 41f3c76912b1b8f6b53546e5aa821b74533c643d | |
| parent | c73eaff2c345237fc94fb3f0fb28e5144b072358 (diff) | |
feat(engine): improve object & resource error messages in opengl rendering backend
| -rw-r--r-- | engine/src/rendering/backend/opengl.rs | 52 | ||||
| -rw-r--r-- | engine/src/rendering/object.rs | 14 |
2 files changed, 41 insertions, 25 deletions
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs index cd53bc5..32afd8f 100644 --- a/engine/src/rendering/backend/opengl.rs +++ b/engine/src/rendering/backend/opengl.rs @@ -223,6 +223,7 @@ impl BackendResourceStore cold_path(); tracing::error!( ?object_id, + %object_kind, "Object does not exist in the rendering object store" ); return None; @@ -232,9 +233,9 @@ impl BackendResourceStore cold_path(); tracing::error!( ?object_id, - expected_object_kind = ?object_kind, - found_object_kind = ?object.kind(), - "Unexpected object kind" + expected_object_kind = %object_kind, + found_object_kind = %object.kind(), + "Unexpected object kind of object in object store" ); return None; } @@ -243,19 +244,16 @@ impl BackendResourceStore let Some(resource) = self.inner.get(resource_id) else { cold_path(); - tracing::error!(?object_id, ?resource_id, "Backend resource does not exist"); - return None; - }; - - if resource.object_kind() != object_kind { - cold_path(); tracing::error!( ?object_id, + %object_kind, ?resource_id, - "Backend resource has wrong associated object kind" + "Backend resource does not exist" ); return None; - } + }; + + debug_assert_eq!(resource.object_kind(), object_kind); Some(resource) } @@ -271,6 +269,7 @@ impl BackendResourceStore cold_path(); tracing::error!( ?object_id, + %object_kind, "Object does not exist in the rendering object store" ); return None; @@ -280,9 +279,9 @@ impl BackendResourceStore cold_path(); tracing::error!( ?object_id, - expected_object_kind = ?object_kind, - found_object_kind = ?object.kind(), - "Unexpected object kind" + expected_object_kind = %object_kind, + found_object_kind = %object.kind(), + "Unexpected object kind of object in object store" ); return None; } @@ -291,19 +290,16 @@ impl BackendResourceStore let Some(resource) = self.inner.get_mut(resource_id) else { cold_path(); - tracing::error!(?object_id, ?resource_id, "Backend resource does not exist"); - return None; - }; - - if resource.object_kind() != object_kind { - cold_path(); tracing::error!( ?object_id, + %object_kind, ?resource_id, - "Backend resource has wrong associated object kind" + "Backend resource does not exist" ); return None; - } + }; + + debug_assert_eq!(resource.object_kind(), object_kind); Some(resource) } @@ -321,8 +317,8 @@ impl BackendResourceStore cold_path(); tracing::error!( ?object_id, - expected_object_kind = ?object_kind, - found_object_kind = ?object.kind(), + expected_object_kind = %object_kind, + found_object_kind = %object.kind(), "Unexpected object kind" ); return; @@ -332,6 +328,7 @@ impl BackendResourceStore let Some(object) = object_store.remove(&object_id).flatten() else { tracing::error!( ?object_id, + %object_kind, "Object does not exist in the rendering object store" ); return; @@ -341,7 +338,12 @@ impl BackendResourceStore let Some(resource) = self.inner.remove(resource_id) else { cold_path(); - tracing::error!(?object_id, ?resource_id, "Backend resource does not exist"); + tracing::error!( + ?object_id, + %object_kind, + ?resource_id, + "Backend resource does not exist" + ); return; }; diff --git a/engine/src/rendering/object.rs b/engine/src/rendering/object.rs index c26b945..61e7ed5 100644 --- a/engine/src/rendering/object.rs +++ b/engine/src/rendering/object.rs @@ -1,4 +1,5 @@ use std::collections::HashMap; +use std::fmt::Display; use std::sync::atomic::{AtomicU64, Ordering}; use crate::asset::Id as AssetId; @@ -121,3 +122,16 @@ pub enum Kind Mesh, Framebuffer, } + +impl Display for Kind +{ + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result + { + formatter.write_str(match self { + Self::Texture => "texture", + Self::ShaderProgram => "shader program", + Self::Mesh => "mesh", + Self::Framebuffer => "framebuffer", + }) + } +} |
