haskell-game / sdl2

Haskell bindings to the SDL2 library
Other
363 stars 87 forks source link

SQL.QuitEvent no longer works #241

Closed unit73e closed 2 years ago

unit73e commented 2 years ago

The SQL.QuitEvent event doesn't seem to work anymore.

I have some sample code here from my repo: https://gitlab.com/unit73e/sdl2-examples/-/blob/master/app/ShowWindow.hs

I'm using Arch Linux with i3wm and closing the window with Shift + Mod + Q (closes a window) doesn't seem to do anything anymore.

I'm not sure what the problem is but I tried downgrading sdl2 to 2.5.3.0 instead of 2.5.3.1 and the problem is the same. In Arch Linux the SDL2 version is 2.0.20.

unit73e commented 2 years ago

It looks like it works with SDL2 2.0.18 and after that it stopped working. At first glance it's a problem with SDL2 but could be an incompatibility with the bindings.

fjvallarino commented 2 years ago

As you suggest, this issue is caused by the latest SDL2 version (you can see a discussion about it on this Monomer issue, which links to another issue on SDL2's repository). The simplest solution is to replace:

events <- SDL.pollEvents

with

events <- SDL.pumpEvents >> SDL.pollEvents

The latest SDL2 (2.0.20) is still supposed to call pumpEvents internally when pollEvent is invoked, but something changed and I'm not sure what triggers it. Explicitly calling pumpEvents once per frame avoids being stuck on the pollEvent call.

unit73e commented 2 years ago

@fjvallarino thanks. I tested your solution and it works. Looks like we'll have to wait for SDL2 team to figure this one out.

dpwiz commented 2 years ago

via #242