Skip to content

[build] Illegal instruction when calling 'ImageResize', related to "Disable UBSAN in zig builds" #3674

@wisonye

Description

@wisonye

Please, before submitting a new issue verify and check:

  • [ x] I tested it on latest raylib version from master branch
  • [ x] I checked there is no similar issue already reported
  • [x ] I checked the documentation on the wiki
  • [ x] My code has no errors or misuse of raylib

Issue description

I'm using the latest master version and zig build to produce raylib/zig-out/libraylib.a, and then I write a simple zig program to load the image and draw texture. Everything works fine except it crashes if calling ImageResize. Here is the console log:

INFO: Initializing raylib 5.1-dev
INFO: Platform backend: DESKTOP (GLFW)
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
INFO: DISPLAY: Device initialized successfully
INFO:     > Display size: 2560 x 1600
INFO:     > Screen size:  1024 x 768
INFO:     > Render size:  1024 x 768
INFO:     > Viewport offsets: 0, 0
INFO: GLAD: OpenGL extensions loaded successfully
INFO: GL: Supported extensions count: 153
INFO: GL: OpenGL device information:
INFO:     > Vendor:   Mesa
INFO:     > Renderer: virgl (AMD Radeon Pro 570X OpenGL Engine (Compat))
INFO:     > Version:  4.0 (Core Profile) Mesa 23.3.1-arch1.1
INFO:     > GLSL:     4.00
INFO: GL: VAO extension detected, VAO functions loaded successfully
INFO: GL: NPOT textures extension detected, full NPOT textures supported
INFO: GL: DXT compressed textures supported
INFO: GL: ETC2/EAC compressed textures supported
INFO: PLATFORM: DESKTOP (GLFW): Initialized successfully
INFO: TEXTURE: [ID 1] Texture loaded successfully (1x1 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 1] Default texture loaded successfully
INFO: SHADER: [ID 1] Vertex shader compiled successfully
INFO: SHADER: [ID 2] Fragment shader compiled successfully
INFO: SHADER: [ID 3] Program shader loaded successfully
INFO: SHADER: [ID 3] Default shader loaded successfully
INFO: RLGL: Render batch vertex buffers loaded successfully in RAM (CPU)
INFO: RLGL: Render batch vertex buffers loaded successfully in VRAM (GPU)
INFO: RLGL: Default OpenGL state initialized successfully
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: TIMER: Target time per frame: 16.667 milliseconds
INFO: FILEIO: [resources/blue_laser.png] File loaded successfully
INFO: IMAGE: Data loaded successfully (53x271 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 3] Texture loaded successfully (53x271 | R8G8B8A8 | 1 mipmaps)
INFO: FILEIO: [resources/lightning_ball.png] File loaded successfully
INFO: IMAGE: Data loaded successfully (848x836 | R8G8B8A8 | 1 mipmaps)
Illegal instruction at address 0x506653
src/external/stb_image_resize2.h:6806:5: 0x506653 in stbir__alloc_internal_mem_and_build_samplers (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/external/stb_image_resize2.h:7603:14: 0x483415 in stbir__perform_build (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/external/stb_image_resize2.h:7639:12: 0x482184 in stbir_build_samplers_with_splits (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/external/stb_image_resize2.h:7649:10: 0x4835c9 in stbir_build_samplers (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/external/stb_image_resize2.h:7666:11: 0x483840 in stbir_resize_extended (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/external/stb_image_resize2.h:7775:9: 0x4866e9 in stbir_resize_uint8_linear (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
src/rtextures.c:1628:53: 0x4a3c4f in ImageResize (/home/wison/zig/raylib-box2d-tutorials/raylib/src/rtextures.c)
/home/wison/zig/raylib-box2d-tutorials/src/temp_test.zig:74:19: 0x27b295 in main (temp-test)
    rl.ImageResize(
                  ^
/home/wison/my-shell/zig-nightly/lib/std/start.zig:585:37: 0x27ba1b in main (temp-test)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7fa9a0274ccf in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fa9a0274ccf` was not available, trace may be incomplete

run temp-test: error: the following command terminated unexpectedly:
/home/wison/zig/raylib-box2d-tutorials/zig-cache/o/58730837b6dcd67266d95753780e6dd9/temp-test
Build Summary: 3/5 steps succeeded; 1 failed (disable with --summary none)
run-temp-test transitive failure
└─ run temp-test failure
error: the following build command failed with exit code 1:
/home/wison/zig/raylib-box2d-tutorials/zig-cache/o/133d2cba4db6e0394cb6df6df719b728/build /home/wison/my-shell/zig-nightly/zig /home/wison/zig/raylib-box2d-tutorials /home/wison/zig/raylib-box2d-tutorials/zig-cache /home/wison/.cache/zig --seed 0x33714a2a run-temp-test

Environment

  • OS : Arch Linux x86_64
  • Linux Kernel : 6.1.68-1-lts
  • Memory : 16.0 GiB
  • CPU: Intel i5-8500 (6) @ 3.000GHz
  • GPU: 01:00.0 Red Hat, Inc. Virtio 1.0 GPU
  • OpenGL : 4.0 (Compatibility Profile) Mesa 23.3.1-arch1.1
  • raylib commit hash ID(latest) : 9f22a4

Code Example

const rl = @cImport({
    @cInclude("raylib.h");
});

const GAME_FPS = 60;

///
///
///
pub fn main() !void {
    // Create a window with a particular size and title
    rl.InitWindow(1024, 768, "Minimal raylib program code template");
    defer rl.CloseWindow();

    // Set refresh rate (AKA, FPS: Frame Per Second)
    rl.SetTargetFPS(GAME_FPS);

    // Set tracing log level (DEBUG/INFO/WARN/ERROR)
    rl.SetTraceLogLevel(rl.LOG_DEBUG);

    //
    // Load image texture
    //
    var laser_sword_image = rl.LoadImage("resources/blue_laser.png");

    //
    // Crash here!!!
    // Crash here!!!
    // Crash here!!!
    //
    rl.ImageResize(@as([*c]rl.Image, @ptrCast(&laser_sword_image)), 20, 100);

    const laser_sword_texture: ?rl.Texture2D = rl.LoadTextureFromImage(laser_sword_image);
    rl.UnloadImage(laser_sword_image);

    //
    // Game loop
    //
    while (true) {
        rl.BeginDrawing();

        // Clear background
        rl.ClearBackground(rl.Color{ .r = 0x23, .g = 0x21, .b = 0x1B, .a = 0xFF });

        // Draw image texture
        if (laser_sword_texture) |texture| {
            rl.DrawTexturePro(
                texture,
                // Texture rect to draw from
                rl.Rectangle{
                    .x = 0.0,
                    .y = 0.0,
                    .width = @as(f32, @floatFromInt(texture.width)),
                    .height = @as(f32, @floatFromInt(texture.height)),
                },
                // Target rect to draw (orgin is TopLeft by default!!!)
                rl.Rectangle{
                    .x = 20.0,
                    .y = 20.0,
                    .width = @as(f32, @floatFromInt(texture.width)),
                    .height = @as(f32, @floatFromInt(texture.height)),
                },
                // Origin offset of the target rect to draw (TopLeft by default)
                rl.Vector2{ .x = 0.0, .y = 0.0 },
                0.0,
                rl.Color{ .r = 0xAC, .g = 0xE6, .b = 0xFE, .a = 0xFF },
            );
        }

        rl.EndDrawing();
    }

    //
    // Unload/clean up resources
    //
    if (laser_sword_texture) |value| rl.UnloadTexture(value);
}

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