a-b-street/abstreet · error · anyhow::Error

error creating texture

Error message

error creating texture: {}

What it means

upload_gl2 uploads a texture using OpenGL 2 / WebGL 2 features (tex_storage_3d, TEXTURE_2D_ARRAY). The first step creates a GPU texture via glow's create_texture(); if the driver or context fails to allocate one, the raw backend error is wrapped in this anyhow message. This indicates a low-level GPU/resource failure during texture upload.

Solutions

  1. Check for GL context loss and recreate the rendering context, then re-upload textures.
  2. Reduce texture count/size (mipmap_levels=2 and RGBA arrays consume memory) to avoid resource exhaustion.
  3. Update GPU/browser drivers or test on different hardware to rule out driver bugs.
  4. Handle the Result from upload_texture and degrade gracefully (e.g., fall back to untextured rendering).

Example fix

// before
let texture_id = unsafe {
    gl.create_texture()
        .map_err(|err| anyhow!("error creating texture: {}", err))?
};
// after: caller-side graceful fallback
if let Err(err) = upload_texture(...) {
    warn!("texture upload failed: {}", err);
    // fall back to untextured rendering or recreate the context
}
Defensive patterns

Strategy: try-catch

Try / catch

// Handle texture upload failure with graceful degradation
if let Err(err) = upload_texture(...) {
    warn!("texture upload failed, continuing without textures: {}", err);
    render_untextured_fallback();
}

Prevention

When it happens

Trigger: upload_texture is called (e.g., for textured triangles or texture arrays) while running on a WebGL 2 / GL 2 context, and gl.create_texture() fails — typically because the GL context is lost or GPU resources are exhausted.

Common situations: Browser tab backgrounded/context lost mid-run; too many large textures exhausting GPU memory; buggy or outdated GPU drivers; headless/software rendering environments without proper GL support.

Related errors


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/076bae62bf209ac2. Report an issue: GitHub.

Appendix: source

Thrown at widgetry/src/backend_glow.rs:634

                for p in sprite_cell.pixels() {
                    texture_bytes.extend_from_slice(&p.2 .0);
                }
            }
        }

        Ok(Self {
            texture_bytes,
            sprite_width,
            sprite_height,
            sprite_count,
        })
    }

    // Utilizes `tex_storage_3d` which isn't supported by WebGL 1.0.
    fn upload_gl2(&self, gl: &glow::Context) -> anyhow::Result<()> {
        let texture_id = unsafe {
            gl.create_texture()
                .map_err(|err| anyhow!("error creating texture: {}", err))?
        };

        let format = glow::RGBA;
        let target = glow::TEXTURE_2D_ARRAY;
        let mipmap_levels: u32 = 2;
        let internal_format = glow::RGBA;

        unsafe {
            gl.bind_texture(target, Some(texture_id));
        }

        // Allocate the storage.
        unsafe {
            gl.tex_storage_3d(
                target,
                mipmap_levels as i32,
                internal_format,
                self.sprite_width as i32,

View on GitHub (pinned to 0964f29315)