We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2325

Summary: SDL_EnableUNICODE sometimes drops keyboard events completely
Product: SDL Reporter: Rafał Mużyło <galtgendo>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: renesd, sezeroz
Version: 1.2.15   
Hardware: x86_64   
OS: Linux   
Attachments: change that sems to make a difference
a slight correction of the previous patch

Description Rafał Mużyło 2013-12-24 04:26:03 UTC
The most annoying part of this bug is that though I've found it in two separate apps, I don't have a trivial testcase for it.

The problem seems to be a condition race, as it's triggered quite randomly (therefore it will be hard to tell whether it really gets fixed, if a probable fix is found).

While it's specific to SDL 1.2, it seems quite similar to the problem described and fixed in http://forums.libsdl.org/viewtopic.php?p=40503.

Now, I should start describing the problem.

A game uses Escape to open menu (the exact key might not be important). Upon opening, it calls SDL_EnableUNICODE(1). Upon closing it calls SDL_EnableUNICODE(0).

I have an IME running.

Game uses SDL_PollEvent to get the events.

If Escape is pressed repeatedly, menu is opened and closed, till it eventually freezes in open state.
"freezes" in this context means "app itself still runs, but no keyboard events are getting delivered (though - for example - mouse events still are)". "getting delivered" should mean "SDL_PollEvent is not receiving any".
If it matters, the last delivered keyboard event is a keypress, the release never arrives.

It seems (no guarantees, due to random nature of the freeze) that unsetting XMODIFIERS (which - AFAIU - will disable IME as far as SDL is concerned) prevents the freeze, therefore the reference to that SDL2 thread.
Comment 1 Rafał Mużyło 2014-01-02 16:05:11 UTC
Created attachment 1510 [details]
change that sems to make a difference

This patch is based on the one in the mentioned above thread. It *seems* to fix the problem.

Of course:
- it's an obvious case of cargo cult, so no idea of how correct it actually is
- given the random nature of the freeze, I'm not even 10% if it really prevent the freeze or simply *significantly* delays it

Though that little note on XEventFilter manpage at the end of description makes me wonder...
Comment 2 Rafał Mużyło 2014-01-29 01:40:55 UTC
Created attachment 1545 [details]
a slight correction of the previous patch

Previous version affected input in the way it shouldn't have - corrected it a little.
Comment 3 Ozkan Sezer 2014-03-17 08:52:49 UTC
I think this is the bug that affects uHexen2:
http://sourceforge.net/p/uhexen2/discussion/425207/thread/6f168cfb/

Is there any intention of fixing it in SDL-1.2?
Comment 4 Sam Lantinga 2014-04-18 05:37:01 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/0aade9c0203f
Comment 6 Ozkan Sezer 2018-08-13 11:46:17 UTC
(In reply to Rene Dudfield from comment #5)
> Arch Linux includes this patch:
> https://git.archlinux.org/svntogit/packages.git/tree/trunk/SDL-1.2.15-
> SDL_EnableUNICODE_drops_keyboard_events.patch?h=packages/sdl

That patch is already in the SDL-1.2 branch.