newsSGE Game Engine - News

 
 

A warning about a Pygame (or SDL?) bug

Item posted by Layla Marchant <onpon4> on Thu 09 Oct 2014 01:54:58 PM UTC.

Today, I noticed something odd and extremely frustrating: when a game I'm working on for Pyweek was switched to and from fullscreen, it was often (seemingly randomly) shutting down all keyboard controls. The game acted like the keyboard didn't exist. This is especially frustrating when the game is in fullscreen, because at that point, X gives the game full control over everything, so there was nothing I could do except reboot with the magic SysRq key.

Well, I did some digging, and I found that it's a Pygame bug, specifically a bug in the pygame.display.set_mode function that occurs when this function is called more than once in a run (removing these calls caused the problem to disappear). It seems to affect all versions of Pygame on my system (Trisquel 6), so it could be that this is an SDL bug (and a quick search for the problem in relation to SDL seems to confirm this).

So, what to do about this? Well, I'm honestly not holding out on the bug being fixed. The Pygame project seems to have been dead for quite some time, and SDL 1.2 (which is what Pygame uses) is an old release which I believe is unmaintained. But we can work around this.

The first way is to never attempt to change the window size or fullscreen state while the game is running. This is absolutely sub-optimal, of course.

The second way is to make it possible to close the game with a mouse click somehow. There could be a close button somewhere, or if the game doesn't use the mouse, clicking can simply cause the close event.

The best solution right now is probably the second workaround: make it possible to exit the game with the mouse and clearly warn players about this problem (and the mouse-exit fallback) in the documentation.

Ultimately, though, the proper solution would be for this bug to be fixed in Pygame or SDL 1.2, wherever the problem lies, so if anyone can do that, please do so.

Update: I originally only observed this problem with Pygame 1.9.2a0, but now I've seen it in Pygame 1.9.1 as well. I'm not sure why I didn't see it previously in Pygame 1.9.1.

Back to the top

Powered by Savane 3.14-8aba.
Corresponding source code