We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3270

Summary: No window on SDL_CreateWindow
Product: SDL Reporter: mydevlists
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2 CC: amaranth72
Version: 2.0.4   
Hardware: x86   
OS: Mac OS X 10.8   

Description mydevlists 2016-02-24 22:25:29 UTC
OS X 10.11.3
SDL2 2.0.4
--- The following code paints a yellow rect, but I do not get a window.
--- Removing the surface code, does not create an empty window either.

#include <stdio.h>
#include <SDL2/SDL.h>

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main ( int argc, char** argv )
{
    SDL_Window * window = NULL;
    SDL_Surface * surface = NULL;

    // initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        printf( "Unable to init SDL: %s\n", SDL_GetError() );
        return 1;
    }

    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    window = SDL_CreateWindow("Hi world!",
                              SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              SCREEN_WIDTH,
                              SCREEN_HEIGHT,
                              SDL_WINDOW_RESIZABLE);
    if (window == NULL)
    {
        printf("Window not created: %s\n",SDL_GetError());
    }
    else
    {
        surface = SDL_GetWindowSurface(window);
        SDL_FillRect(surface,NULL,SDL_MapRGBA(surface->format,255,255,0,255));
        SDL_UpdateWindowSurface(window);
        SDL_Delay(5000);
    }

   SDL_DestroyWindow(window);
   SDL_Quit();


    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}
Comment 1 Alex Szpakowski 2016-02-25 01:39:33 UTC
You need to either call SDL_PollEvent or SDL_PumpEvents regularly (typically you'd call SDL_PollEvent in a while-loop every frame).
Comment 2 Sam Lantinga 2017-08-12 04:43:10 UTC
Alex is right, if you're creating windows on the various platforms you also need to handle window management events otherwise the OS won't be able to complete the operations.