Skip to content

[rtextures] Uninitialized thread-locals in stbi #3282

@jbarthelmes

Description

@jbarthelmes

Issue description

  • I had an issue where textures were loaded upside-down.
  • As it turns out, stb_image has thread-local variables to make an image be flipped after loading here.
  • With -O3, these variables are not initialized and contain garbage. With -O0 they are zeroed apparently.
  • As a result, they evaluate to true and the STBI image loading code took the branch (if (stbi__vertically_flip_on_load)) to vertically flip the image.

Environment

clang 16.0.6 (from zig 0.12.0-dev.252+5dc2db805), mingw64, -O3 (-Doptimize=ReleaseFast)

Code Example

examples/textures/textures_image_loading.c

Suggested Fix

  1. Either the thread-locals are kept and initialized with stbi_set_flip_vertically_on_load_thread before being used, or
  2. I prefer disabling them with #define STBI_NO_THREAD_LOCALS in rtextures.c (1-line PR will follow)

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