fuwaneko
fuwaneko

Reputation: 1165

SDL_PollEvent prevents render unless window moved or resized

I have similar issue to this question, except I use SDL renderer instead of surface. I'm trying to render video using ffmpeg but it doesn't matter what I try to render, even simple SDL_Rect doesn't work. I see only black screen unless I move or resize window, then it immediately starts rendering. If I remove SDL_PollEvent it renders properly. I also tried using software renderer, it behaves the same way. Putting rendering into separate thread doesn't help either.

I'm on macOS with SDL2 installed via Homebrew.

SDL_Window *win = nullptr;
SDL_Renderer *renderer = nullptr;

SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER|SDL_INIT_EVENTS);

win = SDL_CreateWindow("Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_RESIZABLE|SDL_WINDOW_ALLOW_HIGHDPI);
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);

while (true) {
    SDL_Event e;
    if (SDL_PollEvent(&e)) {
        if (e.type == SDL_QUIT) {
            break;
        }
    }

    // update texture data via ffmpeg
    // (code omitted)

    // render
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, video_texture, nullptr, nullptr);
    SDL_RenderPresent(renderer);
}

Upvotes: 1

Views: 907

Answers (3)

Ryan C. Gordon
Ryan C. Gordon

Reputation: 196

This is likely the Mojave bug that was fixed in SDL 2.0.9, fwiw:

https://bugzilla.libsdl.org/show_bug.cgi?id=4272

Upvotes: 1

ubadub
ubadub

Reputation: 3880

I had the same issue, and it was fixed by using the SDL2.framework runtime binary that can be downloaded directly from SDL's website here instead of the package available on brew.

Upvotes: 1

fuwaneko
fuwaneko

Reputation: 1165

After some additional debugging I couldn't find any evidence to what's going on even after digging through SDL sources and looking at SDL_Window and SDL_Renderer structures in runtime. I am using Mojave Beta currently but I observed same behavior on High Sierra before. I tried to create renderer with Metal driver introduced in SDL 2.0.8 and it works properly now, and I observe no difference in SDL runtime structures compared to OpenGL which leads me to a suspicion that it's an OS issue. So I'd advise to use Metal renderer on Mac as a solution and just whenever possible. It's the only API supported by Apple after all.

Upvotes: 1

Related Questions