Bug 664771 - changing workspace during SDL_WM_GrabInput leaves SDL client stuck
Summary: changing workspace during SDL_WM_GrabInput leaves SDL client stuck
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: SDL
Version: 5.7
Hardware: Unspecified
OS: Unspecified
low
medium
Target Milestone: rc
: ---
Assignee: Petr Pisar
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks: 664773
TreeView+ depends on / blocked
 
Reported: 2010-12-21 15:47 UTC by Paolo Bonzini
Modified: 2013-04-15 09:12 UTC (History)
2 users (show)

Fixed In Version: SDL-1.2.10-9.el5
Doc Type: Bug Fix
Doc Text:
Cause Calling SDL_WM_GrabInput() function when SDL window is not viewable, e.g. window is displayed on non-active work place or out of root window. Consequence SDL library and thus current application thread block until window becomes viewable and input can be grabbed. Fix SDL_WM_GrabInput() will return immediately with proper error code signaling the grab has failed. Result Application can continue even if SDL window is not viewable.
Clone Of:
: 664773 665329 733605 1074655 (view as bug list)
Environment:
Last Closed: 2011-08-31 09:15:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
test program (1.63 KB, text/plain)
2010-12-21 15:47 UTC, Paolo Bonzini
no flags Details
Non-interractive test case (3.54 KB, text/plain)
2011-07-20 13:59 UTC, Petr Pisar
no flags Details
Proposed patch (841 bytes, patch)
2011-07-20 14:04 UTC, Petr Pisar
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2011:1233 0 normal SHIPPED_LIVE SDL bug fix update 2011-08-31 09:15:41 UTC
SDL Simple Directmedia Layer 1155 0 None None None Never

Description Paolo Bonzini 2010-12-21 15:47:45 UTC
Created attachment 470009 [details]
test program

Description of problem:
Easily reproducible using Xen's SDL interface (KVM's is probably susceptible as well).  Run this loop in a shell:

    i=0; while sleep 1; do echo $i; i=$((i+1)); done

Change workspace, stay there, go back.  The counter won't advance from the moment you press Ctrl-Alt-Right to the moment you go back to the original workspace and release Ctrl-Alt.

The bug provides a standalone program that demonstrates this bug.

Version-Release number of selected component (if applicable):
SDL-1.2.10-7.el5

How reproducible:
100%

Steps to Reproduce:
1. Compile attached program:
gcc sdl.c `/usr/bin/sdl-config --cflags --libs` -o sdl
2. Run it with >1 workspaces set up.
3. Do Ctrl-Alt-Right and back (making sure Ctrl-Alt are pressed for more than one second)

Actual results:
Counter in the console remains stuck.

Expected results:
Counter in the console proceeds normally.

Additional info:
Patch at attachment 329082 [details] applies.

The bug is also present in RHEL6's libSDL, but SDL mode is not supported by KVM there so it's less severe there.  The bug seems not to be present in upstream SDL 1.3.

Comment 1 Paolo Bonzini 2011-02-28 11:00:14 UTC
Requesting fasttrack since this blocks a Xen bug (bug 664773).  Petr mentioned offline a worry that the blocking loop may be part of API.  However, I believe that this is true only when grab will succeed.  In the GrabNotViewable case, grab cannot succeed.

SDL 1.3 does not block and does not grab in an even more general case (http://hg.libsdl.org/SDL/file/40c9d744e595/src/video/x11/SDL_x11window.c, search for X11_SetWindowGrab).  Whenever the window is not focused the grab will fail (and it obviously isn't focused if it isn't visible).

Comment 2 Petr Pisar 2011-03-01 14:39:29 UTC
src/video/x11/SDL_x11wm.c:X11_GrabInputNoLock() will return SDL_GRAB_OFF, if invalid arguments have been supplied, or if ungrab has been requested.

Otherwise (i.e. grab has been requested) following loop is proceeded:

        for ( ; ; ) {
            result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
                        GrabModeAsync, GrabModeAsync,
                        SDL_Window, None, CurrentTime);
            if ( result == GrabSuccess ) {
                break;
            }
            SDL_Delay(100);
        }

As you can see the function will block until it can grab.

The function is wrapped by X11_GrabInput() that does just a thing: it locks event thread. And public function SDL_WM_GrabInput() (via SDL_WM_GrabInputRaw()) does not check the return value. Also other direct calls inside SDL do not check return value of X11_GrabInputNoLock().

So X11_GrabInputNoLock() return value is directly exported to application, or it's assumed the grab always succeeds.

Underlying X11 function XGrabPointer() can return whole variety of error codes (e.g. AlreadyGrabbed) and SDL does not return on them. So, in my opinion, the loop is intentional and SDL application should expect blocking.

Regarding SDL 1.3: 1.3 branch is incompatible project. You can argue with 1.3 API in 1.2 branch.

You should understand current 1.2 implementation always block and lot of applications can rely on it. Changing behavior in RHEL-5 does not sound well to me.

I will raise a bug to upstream to decide what to do if X11 cannot grab a pointer.

Comment 4 Miroslav Rezanina 2011-07-20 08:41:40 UTC
Hi Petr,
any info on upstream response??

Comment 5 Petr Pisar 2011-07-20 09:21:49 UTC
As you can see from external tracker link, upstream is confident SDL-1.3 will not block, but no resolution about SDL-1.2 has been provided. I will ping upstream again with proposed patch to excite some action.

Comment 6 Petr Pisar 2011-07-20 13:59:53 UTC
Created attachment 514012 [details]
Non-interractive test case

Compile as "gcc $(pkg-config --libs --cflags sdl) -lX11 testcase.c".

Comment 7 Petr Pisar 2011-07-20 14:04:00 UTC
Created attachment 514013 [details]
Proposed patch

Comment 10 Petr Pisar 2011-08-26 08:49:43 UTC
    Technical note added. If any revisions are required, please edit the "Technical Notes" field
    accordingly. All revisions will be proofread by the Engineering Content Services team.
    
    New Contents:
Cause
    Calling SDL_WM_GrabInput() function when SDL window is not
    viewable, e.g. window is displayed on non-active work place
    or out of root window.
Consequence
    SDL library and thus current application thread block until
    window becomes viewable and input can be grabbed.
Fix
    SDL_WM_GrabInput() will return immediately with proper error
    code signaling the grab has failed.
Result
    Application can continue even if SDL window is not viewable.

Comment 13 errata-xmlrpc 2011-08-31 09:15:53 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-1233.html

Comment 14 Petr Pisar 2012-01-02 09:06:54 UTC
Upstream decided not to accept this change into version 1.2 to conserve API.


Note You need to log in before you can comment on or make changes to this bug.