Skip to content

OSMesa headless rendering produces corrupted noise for STL models in Docker #123

@roukmoute

Description

@roukmoute

Environment

  • stl-thumb version: 0.5.0
  • OS: Alpine Linux (Docker container)
  • Rendering backend: OSMesa (headless, no X11/Wayland)
  • Docker image: Based on dunglas/frankenphp:latest-alpine

Problem

When using stl-thumb with OSMesa for headless rendering in a Docker container, complex STL models produce corrupted images that look like TV static noise. Simple models render correctly.

Steps to Reproduce

  1. Run stl-thumb in a headless Docker environment using OSMesa
  2. Render a simple model (e.g., cube with ~12 triangles) → Works fine
  3. Render a complex model (e.g., ~210,000 triangles) → Produces noise

Command used:

stl-thumb input.stl output.png -s 300 -a none

Current example for my case:

docker compose exec app stl-thumb /app/Geekko.stl /app/stl_test_300px.png -s 300 -a none

Expected Behavior

A rendered 3D preview of the STL model.

Actual Behavior

The output image contains random colored pixels resembling TV static/noise instead of the 3D model.

Observations

Model Complexity Triangles Result at 300px Result at 200px Result at 75px
Complex model ~210,000 ❌ Noise ❌ Noise ⚠️ Sometimes works
  • The corruption appears to be related to render size - larger sizes fail more consistently
  • Even at smaller sizes (75-100px), complex models produce inconsistent results
  • The -a none flag (disable antialiasing) was used as recommended for OSMesa
  • Background color FFFFFFFF (RGBA white) was specified

Workaround

Currently disabled STL thumbnail generation and falling back to generic icons until this is resolved.

Additional Context

This might be related to OSMesa's software rendering limitations with large vertex/triangle counts, or memory constraints in containerized environments.

Error Output

thread 'main' panicked at winit-0.26.1/src/platform_impl/linux/mod.rs:619:9:
Failed to initialize any backend! Wayland status: XdgRuntimeDirNotSet X11 status: XOpenDisplayFailed
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: winit::platform_impl::platform::EventLoop::new_any_thread
3: stl_thumb::render_to_image
4: stl_thumb::render_to_file
5: stl_thumb::main

Root Cause

winit panics when no display backend is available, but stl-thumb catches this somehow and continues with corrupted OSMesa rendering.

Expected Behavior

Either:

  1. Exit cleanly with error "No display available, headless rendering not supported"
  2. Or properly fall back to OSMesa headless rendering without corruption

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions