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](https://private-user-images.githubusercontent.com/1455306/294325814-e443b2e7-9f23-449e-9604-d36561605157.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MDU1NzQyNDksIm5iZiI6MTcwNTU3Mzk0OSwicGF0aCI6Ii8xNDU1MzA2LzI5NDMyNTgxNC1lNDQzYjJlNy05ZjIzLTQ0OWUtOTYwNC1kMzY1NjE2MDUxNTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDExOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDAxMThUMTAzMjI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmEwMTRlZTgzM2MyYzUyYTI1MmYzYzI2NGQ0NTdkMmMwNDgzNmMxMzM0YWFlNzk0YTczYjA3NGI5OTc2Nzc3OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.YE1Ucomi2p-EFlVzHiuC5sRlKi6rHHkPN4yJUd54AIc)
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.