I have a minimise/maximise bug in my SDL application that has been driving me nuts! When I minimise the screen and then maximise it again the rendering freezes (ie doesn’t refresh any more). If I re-size the screen the rendering refreshes again. The problem DOESN’T occur when I go from minimised to re-sized, only from minimised to maximised. I have provided a simple code example below which is supposed to make the screen flash through varying shades of grey. When you minimise and maximise you’ll see it freezes…
I’m currently running SDL2.0 v 2.0.3 on Windows 10 machine (experienced the same problem running on previous Windows 7 machine).
Would really appreciate some help. Thanks.
//FLASHING SCREEN CODE
//demonstrates screen freeze when you minimise then maximise the screen…
#include “SDL.h”
#include “SDL_image.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);
SDL_Color screenColour = {0, 0, 0}; //Screen colour which is going to change
//SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); // make the scaled rendering look smoother.
//SDL_RenderSetLogicalSize(pRenderer, WINDOW_WIDTH, WINDOW_HEIGHT);
//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
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;
}