Open TonalidadeHidrica opened 4 years ago
I actually also wouldn't expect SDL_Delay
to block the window from showing, I'm not familiar with the SDL internals either but would think that after the window is created it should be opened and visible. Maybe something has changed? It sounds like the latter example from that page (which then starts to poll for events in a loop) does work? I can update the lesson and code to do that, but was avoiding it in that lesson initially to hold off on talking about event handling
Thanks for the reply. Yeah, avoiding event handling stuff makes easier for the beginner, I agree for that. I'll ask the SDL developers later why does it happen and also ask for a simpler sample without event loop if possible. Maybe rewriting the tutorial can be done afterwards.
Facing this issue. Any updates on this ?
@TonalidadeHidrica thanks for pointing out the StackOverflow article.
Removing SDL_Delay(1000);
and Adding this to main.cpp fixes the problem.
// A basic main loop to prevent blocking
bool is_running = true;
SDL_Event event;
while (is_running) {
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
is_running = false;
}
}
SDL_Delay(16);
}
@AbstractXan Sorry for the late reply. Yeah, the SO article suggests simply adding an event loop.
I was so lazy that I didn't make any contact to SDL developers up until now. But still, it may be useful for beginners if some additional notes are added to the tutorial, telling that one may advance to the next tutorial even if the window did not show up.
~Facing this issue. Any updates on this ?~
@TonalidadeHidrica thanks for pointing out the StackOverflow article.
Removing
SDL_Delay(1000);
and Adding this to main.cpp fixes the problem.// A basic main loop to prevent blocking bool is_running = true; SDL_Event event; while (is_running) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { is_running = false; } } SDL_Delay(16); }
Thanks, I'm using a new M1 MacBook Air and also had this issue but removing the SDL_Delay(1000);
and adding that basic loop solved the issue. Thanks a lot.
~Facing this issue. Any updates on this ?~
@TonalidadeHidrica thanks for pointing out the StackOverflow article.
Removing
SDL_Delay(1000);
and Adding this to main.cpp fixes the problem.// A basic main loop to prevent blocking bool is_running = true; SDL_Event event; while (is_running) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { is_running = false; } } SDL_Delay(16); }
ths a lot, it works~
Also on an M1 machine and had to write this loop in order to get the window to show up. Does anyone know why the SDL_Delay(2000) prevents the window from showing, and why the loop fixes it?
I don't think it has anything to do with SDL_Delay()
. On Mac, the window will not appear unless events are processed. If you don't need an event loop as above, just call SDL_PumpEvents()
once after creating the window.
I tried the tutorial Lesson 1. I successfully compiled the file, but when running, it did not show any window; all that happened was that the terminal stopped for exactly three seconds and then the program ended with exit code 0.
I googled and found a similar issue on StackOverflow: SDL Window Not Showing Up at all. According to the answer, it may be the problem that
SDL_Delay
prevents the window from opening. I tried two source code on the page, one from the question and the other from the answer, then the former does not show the window, while the latter did. So I guess the reason Lesson 1 did not work is the same to that? Maybe it needs to be rewritten.Also, if you don't mind, please tell me why "
SDL_Delay
[blocks] the window gets a chance to show"? I'm completely new to SDL, and I want to understand how does it work, what is going on under the hood.System Information:
The source code I wrote, which did not show a window: