Skip to main content

dear_imgui_wgpu/
error.rs

1//! Error types for the WGPU renderer
2
3use thiserror::Error;
4
5/// Result type for renderer operations
6pub type RendererResult<T> = Result<T, RendererError>;
7
8/// Errors that can occur during rendering operations
9#[derive(Error, Debug)]
10#[non_exhaustive]
11pub enum RendererError {
12    /// Generic error with message
13    #[error("Renderer error: {0}")]
14    Generic(String),
15
16    /// Bad texture error
17    #[error("Bad texture error: {0}")]
18    BadTexture(String),
19
20    /// Invalid render state
21    #[error("Invalid render state: {0}")]
22    InvalidRenderState(String),
23
24    /// Secondary viewport rendering began before the Context frame was reconciled.
25    #[error(
26        "WGPU secondary viewport rendering requires a reconciled frame before platform callbacks"
27    )]
28    FrameNotPrepared,
29
30    /// A frame older than the renderer's active resource epoch was supplied.
31    #[error("WGPU frame epoch {received} is older than active epoch {active}")]
32    FrameEpochOutOfOrder { active: u64, received: u64 },
33
34    /// Detached work belongs to another consumer incarnation of its Context.
35    #[error("snapshot consumer generation {actual} does not match executor generation {expected}")]
36    SnapshotConsumerGeneration { expected: u64, actual: u64 },
37
38    /// A target was replaced, retired, or belongs to another executor.
39    #[error("detached WGPU target for viewport {viewport:?} is stale or foreign")]
40    StaleSnapshotTarget { viewport: dear_imgui_rs::Id },
41
42    /// Exhausted target identities cannot be reused by queued snapshots.
43    #[error("detached WGPU target resource generation space is exhausted")]
44    SnapshotTargetGenerationExhausted,
45
46    /// The renderer has not been attached to a Dear ImGui context.
47    #[error("WGPU renderer is not bound to a Dear ImGui context")]
48    ContextNotBound,
49
50    /// The Dear ImGui context used to initialize the renderer has been dropped.
51    #[error("the Dear ImGui context bound to this WGPU renderer has been dropped")]
52    ContextDropped,
53
54    /// A context-taking operation received a context other than the renderer owner.
55    #[error("WGPU renderer received a different Dear ImGui context than its bound context")]
56    ContextMismatch,
57
58    /// The context already has renderer-owned state that this renderer cannot claim safely.
59    #[error("Dear ImGui context is already configured for a renderer backend")]
60    ContextAlreadyHasRenderer,
61
62    /// Renderer-owned Dear ImGui state changed while this renderer remained attached.
63    #[error("WGPU renderer lost ownership of Dear ImGui field `{field}`")]
64    RendererStateDrift { field: &'static str },
65
66    /// Draw buffer length exceeds renderer index ranges.
67    #[error("{buffer} draw buffer length exceeds renderer limits")]
68    DrawBufferTooLarge { buffer: &'static str },
69
70    /// Draw buffer offset overflowed while accumulating draw lists.
71    #[error("{buffer} draw buffer offset overflow")]
72    DrawBufferOffsetOverflow { buffer: &'static str },
73
74    /// A draw command addresses indices outside its parent draw list.
75    #[error("draw command index range {start}..{end} exceeds its parent index buffer length {len}")]
76    DrawCommandIndexRangeOutOfBounds {
77        start: usize,
78        end: usize,
79        len: usize,
80    },
81
82    /// A draw command references a vertex outside its parent draw list.
83    #[error(
84        "draw command references vertex {index}, but its parent vertex buffer has length {len}"
85    )]
86    DrawCommandVertexOutOfBounds { index: usize, len: usize },
87
88    /// Native raw draw callbacks cannot be invoked by this target.
89    #[error("raw draw callbacks are not supported by the WGPU renderer on this target")]
90    RawDrawCallbackUnsupported,
91
92    /// WGPU textures do not carry sampler state; select linear or nearest explicitly.
93    #[error("texture-owned sampler commands are not supported by the WGPU renderer")]
94    TextureSamplerUnsupported,
95
96    /// Buffer creation failed
97    #[error("Buffer creation failed: {0}")]
98    BufferCreationFailed(String),
99
100    /// Texture creation failed
101    #[error("Texture creation failed: {0}")]
102    TextureCreationFailed(String),
103
104    /// Pipeline creation failed
105    #[error("Pipeline creation failed: {0}")]
106    PipelineCreationFailed(String),
107
108    /// Shader compilation failed
109    #[error("Shader compilation failed: {0}")]
110    ShaderCompilationFailed(String),
111
112    /// WGPU error
113    #[error("WGPU error")]
114    Wgpu(#[from] wgpu::Error),
115
116    /// Invalid texture ID
117    #[error("Invalid texture ID: {0:?}")]
118    InvalidTextureId(dear_imgui_rs::TextureId),
119
120    /// The process-wide renderer texture identifier space is exhausted.
121    #[error("WGPU texture identifier space is exhausted")]
122    TextureIdExhausted,
123
124    /// An external texture handle does not belong to this renderer or was already removed.
125    #[error("external WGPU texture is not registered: {0:?}")]
126    ExternalTextureNotFound(dear_imgui_rs::TextureId),
127
128    /// An external view mapping cannot advance its revision without reusing an old revision.
129    #[error("external WGPU texture binding revision space is exhausted: {0:?}")]
130    ExternalTextureRevisionExhausted(dear_imgui_rs::TextureId),
131
132    /// A managed update arrived after the renderer lost its matching GPU resource.
133    #[error(
134        "managed texture {0:?} has no WGPU resource; reset renderer bindings to request a full create"
135    )]
136    ManagedTextureMissing(dear_imgui_rs::render::SnapshotTextureId),
137
138    /// A managed identity was reused with incompatible dimensions.
139    #[error(
140        "managed texture {texture:?} layout changed without a new identity: expected {expected:?}, got {actual:?}"
141    )]
142    ManagedTextureLayoutMismatch {
143        texture: dear_imgui_rs::render::SnapshotTextureId,
144        expected: [u32; 2],
145        actual: [u32; 2],
146    },
147
148    /// Context-owned renderer consumer state rejected the operation.
149    #[error(transparent)]
150    RendererConsumer(#[from] dear_imgui_rs::render::RendererConsumerError),
151
152    /// Managed frame finalization or texture-request capture failed.
153    #[error(transparent)]
154    FrameCapture(#[from] dear_imgui_rs::render::SnapshotError),
155
156    /// Context attachment registration rejected the renderer's deferred-drop cleanup hook.
157    #[error(transparent)]
158    ContextAttachment(#[from] dear_imgui_rs::ContextAttachmentError),
159
160    /// A request was completed with the wrong feedback kind.
161    #[error(transparent)]
162    TextureFeedback(#[from] dear_imgui_rs::render::TextureFeedbackError),
163}
164
165// Display and Error traits are automatically implemented by thiserror