Rust-SDL2 / rust-sdl2

SDL2 bindings for Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sdl2 gfx demo random pixels : macbook air M2

emyr666 opened this issue · comments

I have a Macbook Air M2. I use brew to install sdl2 and have 2.28.5. examples/gfx-demo.rs compiles and runs. When I click in the screen it draws lines but there are large square pixel blocks that have random colours. This seems to suggest some kind of initialisation bug where its not zeroing things before drawing.

Cargo.toml...

[package]
name = "gfxdemo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies.sdl2]
version = "0.36"
default-features = false
features = ["gfx"]
Screenshot 2024-01-05 at 00 58 51

Can you reproduce this if you write this in C? It might be a SDL2 bug and not a rust-sdl2 bug itself (although it might be).

Yep...same behaviour with this program so its an SDL issue not a rust issue. You can close this.

// a simple sdl program
// create a window and do some random lines

#include <random>

#include <SDL2/SDL.h>

double rng() {
    static std::random_device rd;
    static std::mt19937 mt(rd());
    static std::uniform_real_distribution<> dist(0, 1);
    return dist(mt);
}

int main(int argc, char *argv[]){
    rng();
    const Uint32 WIDTH=800;
    const Uint32 HEIGHT=600;
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window* window = SDL_CreateWindow(
        "Random Lines",
        SDL_WINDOWPOS_UNDEFINED,
        SDL_WINDOWPOS_UNDEFINED,
        WIDTH,
        HEIGHT,
        SDL_WINDOW_SHOWN);
    SDL_Renderer*renderer = SDL_CreateRenderer(
        window,
        -1,
        SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
    SDL_RenderClear(renderer);
    bool quit = false;
    SDL_Event event;
    while(!quit){
        while(SDL_PollEvent(&event)){
            switch(event.type){
                case SDL_QUIT:
                    quit = true;
                    break;
            }
        }
        // draw rndom line
        Uint32 x1 = rng()*WIDTH;
        Uint32 x2 = rng()*WIDTH;
        Uint32 y1 = rng()*HEIGHT;
        Uint32 y2 = rng()*HEIGHT;
        Uint32 col = rng()*0xFFFFFF;
        Uint8 red = rng()*0xFF;
        Uint8 green = rng()*0xFF;
        Uint8 blue = rng()*0xFF;
        SDL_SetRenderDrawColor(renderer, red, green, blue, 0);
        SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
        SDL_RenderPresent(renderer);
    }
    SDL_Quit();
    return 0;
}

Or more likely...a bug in the apple metal framework which i think SDL2 hooks into.