SDL2 - Can't see the Window

Hi all,

Running into a problem with SDL2- when I make a window, I can’t see it! I’m running the latest version of Mac OS X.

I’m trying to follow the Lazy Foo tutorials here

I’ve also read the docs for SDL_CreateWindow here

I’ve tried the Lazy Foo tutorials for Mac OS X using Xcode, as well as building SDL2 myself (following the Linux tutorials) and running it. I’ve also tried the code from the SDL_CreateWindow docs page.

I have no problems compiling. It compiles fine. When I run it, whether with ./01_hello_SDL or hitting the play button in XCode, I can see that something runs (the spinning wheel comes up in the GUI for Xcode or in the top right of terminal when running with ./filename). However, I don’t see any window or image popup.

What am I doing wrong?

Thanks for the help!

Ok, I found the issue. The window wouldn’t show up on OS X unless I had an event loop going (prior I had an SDL_Delay call).

Now I’m curious- why do I need the event loop? Why isn’t the SDL_Delay sufficient?

(LazyFoo gives an example of the event loop on this page.)

@kotrunga I had this issue as well, did you learn why?
thanks!

There’s some window sizing and state change stuff that MacOS puts on the event queue that most likely needs to get consumed and removed from the event queue before the OS considers the window “finished” and shows it, or something along that line.

A quick little test app with SDL 2.0.10 run on MacOS 10.15.1 shows that there were 5 events waiting in the queue right after the window was created: SDL_WINDOWEVENT_FOCUS_GAINED, SDL_WINDOWEVENT_ENTER, SDL_MOUSEMOTION, SDL_WINDOWEVENT_SHOWN, SDL_WINDOWEVENT_EXPOSED.

In a normal game or app, this isn’t a problem since you’re going to set up an event queue anyway.

Thanks for explaining , got a bit confused why the problem occurred. Always good to know why things happen.

Yes I agree with that the event loop will most likely be added in most cases.

If memory serves, this wasn’t always the case on MacOS, which is why older tutorials don’t mention it.

I think you are correct, I used a little bit of SDL2 in my university studies and I can’t recall that this happed back then :smiley:

@sjr thanks for helping @viking and me!

No problem! Glad to help.