2
\$\begingroup\$

I have a simple SDL application with a re-sizeable window. If I minimize it and then maximize the window the rendering freezes. I've included a simple code example below which makes the screen flash through varying shades of grey. Try minimizing and then maximizing the window, and you can see that the rendering halts while the window is resizing. How do I stop the rendering freezing when going from minimized to maximized?

//FLASHING SCREEN CODE
//Demonstrates screen freeze when you minimise then maximise the screen....

#include "SDL.h"

using namespace std;

int main( int argc, char* args[] )
{
    //Initialise SDL2, declare Window + Renderer
    SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ); //Initialize SDL for video and audio
    SDL_Window* pWindow = NULL;
    SDL_Renderer* pRenderer = NULL;
    pWindow = SDL_CreateWindow("Minimise Maximise Test", 50, 50, 1200, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED);
    pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_TARGETTEXTURE);

    //The Screen colour which is going to flash through different shades of grey
    SDL_Color screenColour = {0, 0, 0};

    //SDL event for detecting X-out (quit)
    SDL_Event event;
    bool quit = false;

    //Loop
    while( quit == false )   //While SDL has not been X'ed out
    {
        //Handle quit
        if (SDL_PollEvent(&event) != 0)
        {
            if(event.type == SDL_QUIT) quit = true; //Press X-out to quit (but not visible on fullscreen)
        }

        //Make screen flash by changing its colour through shades of grey
        screenColour.r++;
        screenColour.g++;
        screenColour.b++;

        //Render the screen
        SDL_SetRenderDrawColor(pRenderer, screenColour.r, screenColour.g, screenColour.b, 255);
        SDL_RenderFillRect(pRenderer, NULL);
        SDL_RenderPresent(pRenderer); //like SDL_flip
    }

    //Shutdown
    SDL_DestroyRenderer(pRenderer);
    SDL_DestroyWindow(pWindow);
    SDL_Quit();

    return 0;
}

I'm currently running SDL2.0 v 2.0.3 on Windows 10 machine (experienced the same problem running on previous Windows 7 machine).

\$\endgroup\$
  • \$\begingroup\$ Just to clarify: Are you talking about the freeze that happens while the window size changes? Also, why is this behaviour an issue? \$\endgroup\$ – Tyyppi_77 Aug 5 '16 at 13:03
  • \$\begingroup\$ I've wrote an answer to a similar question on StackOverflow: stackoverflow.com/a/51597338/1021959. It uses WinAPI messages and timers. \$\endgroup\$ – Bernard Jul 30 '18 at 15:39
1
\$\begingroup\$

This is not something you can do, at least not using pure SDL. This seems to be a bug in SDL, which apparently is not fixed yet. However, at least to me, this isn't a huge issue, but perhaps this annoys you.

I tried tinkering around SDL with specific WinAPI calls and ugly hacks to access the Windows message loop, but I was unable to get any results. SDL simply seems to halt the game process while the window is being resized and dragged, and there really isn't much you can do about it.

If you feel confident working using the Windows API and WM events, you might want to investigate how you could get a hand on those events before SDL does, but that will of course drop your multi-platform support that you gained with choosing SDL as your windowing library.

\$\endgroup\$
  • 1
    \$\begingroup\$ This isn't really a bug in SDL, unless you consider not working around a design flaw in win32 to be a bug. The problem is that when using the win32 API directly, window move/resize operations are usually handled by calling DefWindowProc. Unfortunately, this function blocks until the move/resize operation completes (internally, it sets up a separate temporary message pump for handling events until you release the mouse button). The end result is your main thread stalls when moving or resizing the window. \$\endgroup\$ – bcrist Aug 6 '16 at 1:37
  • \$\begingroup\$ If there's a bug item in the library's bug tracking service, I consider the behaviour a bug. Nice to hear about the underlying tech though, thanks! \$\endgroup\$ – Tyyppi_77 Aug 6 '16 at 7:39

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.