Search code examples
c++sdlsdl-2

SDL Window not clickable (minimize and close button not working)


When the SDL Window opens, I can't click anything on the window and my cursor is the blue loading cursor. So, when I try to minimize the window, it doesn't do anything. Help!

Code:

#include "SDL.h"

int main(int argc, char *argv[])  {
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = SDL_CreateWindow("Title",
            SDL_WINDOWPOS_CENTERED,
            SDL_WINDOWPOS_CENTERED,
            640, 480,
            SDL_WINDOW_SHOWN);

    SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);

    SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);

    SDL_RenderClear(renderer);

    SDL_RenderPresent(renderer);

    SDL_Delay(3000);

    return 0;
}

I use a MinGW Compiler, my IDE is Eclipse, and the version of the SDL is 2.0.12.


Solution

  • SDL_Delay blocks the main thread until it returns. On Windows, the main thread of an application should process and respond to the Windows messages to do anything, otherwise it is marked as "not responding". Since the thread is blocked, that's what happens.

    SDL handles that within its events system, which you should call into with an event loop calling SDL_PollEvent.