haskell-game / sdl2

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

Fix event polling #242

Closed hanst99 closed 2 years ago

hanst99 commented 2 years ago

pollEvents was apparently broken by a recent-ish patch to SDL.

This should fix that. As an aside, this attempts to make polling events a bit more efficient; We just statically allocate a single buffer for events (AFAIK you can only call Poll from the main thread anyway, so the fact that this isn't thread safe shouldn't be an issue), this way we avoid a bunch of unnecessary heap allocations we'd normally get via alloca.


I hope adding the pumpEvents call should be relatively noncontroversial, if people don't like the other bit I'll remove it. T reason I've added it is that the previous implementation would call PollEvent twice and allocatea once for each event, which is quite a loss because PollEvent needs to lock the event queue each time it's called and alloca adds additional GC garbage. This is probably not the one thing that makes/breaks anyone's performance targets, but it is unnecessary extra work.

Fixes issues like:

https://github.com/haskell-game/sdl2/issues/241