libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.79k stars 1.82k forks source link

SDL_PollEvent gives a sentinel event and returns true #11319

Open oh-facts opened 4 hours ago

oh-facts commented 4 hours ago

My game was working fine before. Then I updated my sdl and I noticed that my game was stuck in an infinite loop. Upon further investigation I found that control was stuck inside my event loop and it wouldn't break out because of a sentinel event.

SDL_Event sdl_event;
while (SDL_PollEvent(&sdl_event)) 
{
  if(sdl_event.type == SDL_EVENT_POLL_SENTINEL)
  {
   // I stepped through with a debugger to make sure that this was the reason
    break;
  }
  switch(sdl_event.type)
  {
   // handle other events
  }
}       

I haven't needed to break out explicitly before using the poll sentinel event. Also, I checked and the sentinel event is internal and ideally I shouldn't need to interact with it at all.

I made no changes to my code either, I just updated SDL.

The SDL3 commit is 638b50b69be6dd158e89d462dc786c067fc9e7ba. Also, SDL3 is built as a static library and the CRT is linked statically and this is debug mode. I compiled using the msvc compiler. This is C++.

PS: I explored a little more and I am quite confused now.

image image

Control is in the return false bit.

So, the event is a sentinel event, and false should be returned, right?

Here, is the part I don't get it.

image image

Why is res = 1 ? It clearly returned false right?

Let me know if I should provide more information.

Thank you.

oh-facts commented 2 hours ago

I did some more work. So, this works fine with SDL2.

I don't think static linking is the issue here, since I used the same config for the sdl2 version (msvc, debug mode, static crt, static lib, C++).

I think it has to do something with that commit.

slouken commented 1 hour ago

Can you reproduce it with an SDL test program? Most of them have that kind of loop structure.