Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdl2 gfx demo random pixels : macbook air M2 #1360

Open
emyr666 opened this issue Jan 5, 2024 · 3 comments
Open

sdl2 gfx demo random pixels : macbook air M2 #1360

emyr666 opened this issue Jan 5, 2024 · 3 comments

Comments

@emyr666
Copy link

emyr666 commented Jan 5, 2024

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
@Cobrand
Copy link
Member

Cobrand commented Jan 5, 2024

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).

@emyr666
Copy link
Author

emyr666 commented Jan 5, 2024

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;
}

@emyr666
Copy link
Author

emyr666 commented Jan 5, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants