1

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);
}
3
  • 2
    Any reason for only processing a single event per present? The usual approach is to use a while(SDL_PollEvent(&e))-type loop to completely empty the event queue each frame.
    – genpfault
    Aug 24, 2018 at 0:52
  • @genpfault thanks for the suggestion, I tried that approach, doesn't help either. Besides, I currently have separate render thread, so main loop consists only of SDL_PollEvent and it still starts to render only if I move or resize window.
    – fuwaneko
    Aug 24, 2018 at 10:28
  • 1
    I suppose it is the time for MCCVE then, as well as description of your OS/gfx driver versions. Threading also might be where your problem originates from.
    – keltar
    Aug 24, 2018 at 17:51

3 Answers 3

1

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.

1

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.

1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.