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 - No window on SDL_CreateWindow
Summary: No window on SDL_CreateWindow
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.4
Hardware: x86 Mac OS X 10.8
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-02-24 22:25 UTC by mydevlists
Modified: 2017-08-12 04:43 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.