Skip to content
dream-soft-render
api

Errors

Error and VertexField: every variant, which calls return it, and the text it displays.

Error#

#[non_exhaustive] pub enum Error

Why a call was refused. A call that returns an Error has drawn and changed nothing. Clone, Debug, PartialEq, Eq, Display, std::error::Error. It is #[non_exhaustive]: match it with a wildcard arm.

VariantReturned byWhenDisplays
SurfaceSize { width: usize, height: usize }begin_frameThe pixel count overflows or exceeds MAX_SURFACE_PIXELS, or a side is longer than 65535 pixelssurface size 1281x720 overflows, exceeds the pixel budget, or is longer than 65535 pixels on a side
TextureSize { width: usize, height: usize }create_textureA side is zero or longer than 65536 texels, or the byte size overflowstexture size 0x4 is empty, overflows, or is longer than 65536 texels on a side
PixelDataLength { expected: usize, actual: usize }create_texture, update_textureThe pixel data is not width × height × 4 bytespixel data is 15 bytes, expected 16
TextureBudget { requested: usize, budget: usize }create_textureThe renderer’s textures would total more than MAX_TEXTURE_BYTES. requested is that totaltexture storage would need 8388612 bytes, over the 8388608 byte budget
UnknownTexture(TextureId)update_texture, free_texture, textured_rect, meshThe handle was freed, or another renderer issued itunknown or freed texture #6
TextureIdsExhaustedcreate_textureEvery handle from 0 to u64::MAX - 1 has been issued in this processevery texture handle has been issued
TextureUpdateOutOfBounds(TextureId)update_textureThe region does not fit inside the texture, or its byte size overflowsupdate region exceeds the bounds of texture #6
NonFiniteRectfill_rect, textured_rectA coordinate of the rectangle or its UV range is NaN or infiniterectangle has a non-finite coordinate
NonFiniteVertex { index: usize, field: VertexField }meshVertex index has a NaN or infinite position or texture coordinatemesh vertex 2 has a non-finite texture coordinate
IndexCount(usize)mesh; render_egui, inside an I/O errorThe index count is not a multiple of threemesh has 5 indices, not a multiple of three
IndexOutOfRange { index: u32, vertex_count: usize }mesh; render_egui, inside an I/O errorAn index is past the last vertexmesh index 3 is out of range for 3 vertices
Raster(String)The From<std::io::Error> conversionCarries an I/O error’s messagerasterizer error: and the message

The drawing API never returns Raster on 32- and 64-bit targets. The conversion exists so a function that returns Error can use ? on render_egui, whose errors are std::io::Error.

The index errors reach render_egui’s caller wrapped in an std::io::Error, and can be taken back out:

use dream_soft_render::Error;

fn describe(error: &std::io::Error) -> String {
    match error
        .get_ref()
        .and_then(|inner| inner.downcast_ref::<Error>())
    {
        Some(Error::IndexOutOfRange {
            index,
            vertex_count,
        }) => {
            format!("an egui mesh used vertex {index} of {vertex_count}")
        }
        Some(other) => other.to_string(),
        None => error.to_string(),
    }
}

fn main() {
    let error = std::io::Error::other(Error::IndexOutOfRange {
        index: 9,
        vertex_count: 4,
    });
    assert_eq!(describe(&error), "an egui mesh used vertex 9 of 4");
}

VertexField#

pub enum VertexField { Position, Uv }

The part of a vertex Error::NonFiniteVertex names: Position for Vertex::pos, Uv for Vertex::uv. A color cannot be invalid; every bit pattern is a color. Clone, Copy, Debug, PartialEq, Eq, Hash, and Display as position or texture coordinate.