dear_imgui_rs/texture/
error.rs1use thiserror::Error;
2
3use super::{ManagedTextureId, TextureRegion, TextureStatus};
4use crate::ContextId;
5
6#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
8#[non_exhaustive]
9pub enum TextureDataError {
10 #[error("texture dimensions must be positive (got {width}x{height})")]
12 InvalidDimensions {
13 width: u32,
15 height: u32,
17 },
18
19 #[error("texture width {0} exceeds Dear ImGui's signed dimension range")]
21 WidthOutOfRange(u32),
22
23 #[error("texture height {0} exceeds Dear ImGui's signed dimension range")]
25 HeightOutOfRange(u32),
26
27 #[error(
29 "texture byte size is not representable: {width}x{height} pixels at {bytes_per_pixel} bytes per pixel"
30 )]
31 ByteSizeOutOfRange {
32 width: u32,
34 height: u32,
36 bytes_per_pixel: usize,
38 },
39
40 #[error(
42 "texture metadata is invalid: width={width}, height={height}, bytes_per_pixel={bytes_per_pixel}"
43 )]
44 InvalidLayout {
45 width: i32,
47 height: i32,
49 bytes_per_pixel: i32,
51 },
52
53 #[error("texture payload length mismatch: expected {expected} bytes, got {actual}")]
55 ByteLengthMismatch {
56 expected: usize,
58 actual: usize,
60 },
61
62 #[error("texture cannot be mutated while its status is {0:?}")]
64 InvalidStatus(TextureStatus),
65
66 #[error("texture status {0:?} has no CPU pixel storage")]
68 MissingPixelStorage(TextureStatus),
69
70 #[error("full texture update {width}x{height} cannot be represented by TextureRect")]
72 FullUpdateRectOutOfRange {
73 width: u32,
75 height: u32,
77 },
78
79 #[error("texture update region dimensions must be positive (got {width}x{height})")]
81 InvalidRegionDimensions {
82 width: u32,
84 height: u32,
86 },
87
88 #[error("texture update region {region:?} exceeds texture bounds {width}x{height}")]
90 UpdateRegionOutOfBounds {
91 region: TextureRegion,
93 width: u32,
95 height: u32,
97 },
98
99 #[error("texture update region cannot be represented by the native update queue: {0:?}")]
101 UpdateRegionNotRepresentable(TextureRegion),
102
103 #[error("texture row pitch {actual} is smaller than the required {minimum} bytes")]
105 RowPitchTooSmall {
106 minimum: usize,
108 actual: usize,
110 },
111
112 #[error(
114 "texture subresource payload size overflowed for row pitch {row_pitch} and height {height}"
115 )]
116 PayloadSizeOutOfRange {
117 row_pitch: usize,
119 height: u32,
121 },
122}
123
124#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
126#[non_exhaustive]
127pub enum ManagedTextureError {
128 #[error("managed texture belongs to Context {actual:?}, not Context {expected:?}")]
130 ForeignContext {
131 expected: ContextId,
133 actual: ContextId,
135 },
136
137 #[error("managed texture handle has an unknown slot: {0:?}")]
139 UnknownSlot(ManagedTextureId),
140
141 #[error("managed texture handle has a stale generation: {0:?}")]
143 StaleGeneration(ManagedTextureId),
144
145 #[error("managed texture is retiring: {0:?}")]
147 Retiring(ManagedTextureId),
148
149 #[error("managed texture removal was already requested: {0:?}")]
151 AlreadyRetiring(ManagedTextureId),
152
153 #[error("managed texture was already removed: {0:?}")]
155 AlreadyRemoved(ManagedTextureId),
156
157 #[error("font-atlas texture belongs to a different Context atlas")]
159 ForeignFontAtlas,
160
161 #[error("managed texture feedback contains a duplicate handle: {0:?}")]
163 DuplicateFeedback(ManagedTextureId),
164
165 #[error("managed texture feedback for {id:?} used invalid status {status:?}")]
167 InvalidFeedbackStatus {
168 id: ManagedTextureId,
170 status: TextureStatus,
172 },
173}
174
175#[derive(Clone, Copy, Debug, Eq, Error, PartialEq)]
177#[non_exhaustive]
178pub enum ManagedTextureMutationError {
179 #[error(transparent)]
181 Access(#[from] ManagedTextureError),
182
183 #[error(transparent)]
185 Data(#[from] TextureDataError),
186}