Re: [AD] Real weird unix bug, help wanted

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Wed, 2006-03-01 at 22:08 +0100, Hans de Goede wrote:
> Hi,
> 
> First a short intro I'm a volunteer software packager for the Fedora 
> Linux Distro and I've recently been packaging allegro using software.
> I've already send 2 patches for bugs I found to the list, one for digmid 
> and one for alsa sound on bigendian machines.
> 
> I've spend my last 2 days debugging a real weird problem and any 
> help/input is appreciated.
> 
> There is a problem (under unix using the X11-system driver) when calling
> set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, ... when changing from a 
> windowed display to a fullscreen display.
> 
> I'm not at all sure that this is allegro's fault it might very well be 
> the brand spanking new modular Xorg 7.0 release I'm using. While we're 
> on the topic, I'm using (and you might need an exact copy to reproduce):
> -athlon64 2800+
> -radeon 9250 / 9200pro with 256 mb ram
> -latest x86_64 (64 bits) version of Fedora (FC5test3 + updates)
> -using gnome with the (default) metacity window manager.
> -allegro-4.2.0-8 as packaged by Fedora-Extras
> 

[..]

Only similarity i see here is, i'm also using Gnome+Metacity

> 
> This should create an unmanaged window with its left top at position 0.0 
> of the root window. Now the problem is that with one allegro using 
> program, sometimes it is as if the XMoveWindow call and the XGrabPointer 
> call fail silently. In this case the window is at its last position 
> (before the set_gfx_mode call) and the mouse is ungrabbed, thus I can 
> pan around the rest of my desktop. It is as if both the move and the 
> mousegrab never happened. Strange enough the keyboardgrab has happened.

Yeah, I've been seeing this problem for some time here, on both the old
XFree86 and now on X.org. The attached program is how far I got with
tracking this further.. but my conclusions was, X11 really is weired
(e.g. removing one of the XSync in that program makes it not work, and I
have no idea why I would need to set the type to DOCK to get fullscreen,
not do I know why I need the XGrabKeyboard, but oh well..)

> I've attached a very much minimized version of the program causing this 
> problem and I've also found a workaround. There is a define called 
> workaround in the top of the file, comment this to get the buggy 
> behaviour. Once you have the file compiled with the workaround define 
> commented press any key todo the fullscreen<->window toggle. Within say 
> 10 toggle you should see the unwanted behaviour of the window not being 
> at 0.0 (the viewport will be there) and then you can also freely cause 
> the mouse to move outside the window and thus the viewport to scroll.
> 
> The workaround consists of waiting for the key which was pressed to be 
> released before doing the switch. Don't ask me why but this fixes it (it 
> took me ages (hours) to find this, looking at how other programs without 
> the problem did it).

Unfortunately, it makes no difference here :/

> I've also written an alternative workaround which works from within 
> allegro, add the following lines right before the XMoveWindow call:
>        /* HACK HACK HACK, XMoveWindow and XGrabPointer seem to fail
>           (silently!)  when called on a window when keys are still
>           pressed. */
>        do {
>          char keys[32];
>          XQueryKeymap(_xwin.display, keys);
>          for (i=0; (i<32) && (keys[i]==0); i++) {}
>        } while(i<32);
> 
>        /* Hack: make the window fully visible and center cursor.  */
>        XMoveWindow(_xwin.display, _xwin.window, 0, 0);
> 
> 
> Notice that I've also put the XMoveWindow call above for clearity, you 
> only need this once! I do not advocate this fix as a good one, nor 
> advice to include it in allegro. Its just extra info.

Same for this. Maybe it happens somewhat less often, but it definitly
still happens. And even if it worked, the next time it may fail again.

I also tried #define workaround and the above, and putting
remove_keyboard()/install_keyboard() around set_gfx_mode() - all without
effect. Even not installing any keyboard (and switching with
rest(3000)), it happens - with and without the modified xwin.c.

Of course, I might have done something wrong and always used the same
executable, it's quite late already :P And it still could have to do
with the keyboard..

> I hope someone can help (if anyone can reproduce this please let me 
> know, that alone would be great, esp with an other X-server (version) 
> then we can rule out certain things).
> 
> I know the attached test-case isn't all that simple but it is as good as 
> it gets, its much smaller then the original game having the problem.

Yes, it's a good test case, it reproduces it for me like each other
time, or maybe even 2/3 of time and only works correctly sometimes.

Anyway, now that you mention this, we should try to fix it. The first
thing I can think of is to try it outside of Gnome.

Any maybe should investigate more my attached test code? I was to
eventually get back to it myself, but not sure when.

Or it could be an actual bug in the Allegro code - but I don't know
where to start looking.

-- 
Elias Pschernig
#include <allegro.h>
#include <xalleg.h>
#include <stdio.h>

static void switch_fullscreen(void)
{
    char *names[] = {
        "ATOM",
        "_NET_WM_STATE",
        "_NET_WM_STATE_FULLSCREEN",
        "_NET_WM_WINDOW_TYPE",
        "_NET_WM_WINDOW_TYPE_DOCK"
    };
    Atom atoms[sizeof(names) / sizeof(names[0])];

    XLOCK();
    XInternAtoms(_xwin.display, names, sizeof(names) / sizeof(names[0]), 1, atoms);
    XUnmapWindow(_xwin.display, _xwin.window);
    XFlush(_xwin.display);
    XChangeProperty(_xwin.display, _xwin.window, atoms[1], atoms[0], 32, PropModeReplace,
        (unsigned char *)&atoms[2], 1);
    XChangeProperty(_xwin.display, _xwin.window, atoms[3], atoms[0], 32, PropModeReplace,
        (unsigned char *)&atoms[4], 1);
    XFlush(_xwin.display);
    XMapWindow(_xwin.display, _xwin.window);
    XFlush(_xwin.display);

    XGrabKeyboard(_xwin.display, XDefaultRootWindow(_xwin.display), False,
        GrabModeAsync, GrabModeAsync, CurrentTime);

    XUNLOCK();
}

int main(void)
{
    allegro_init();
    install_timer();
    install_keyboard();
    int w, h;
    get_desktop_resolution(&w, &h);
    set_color_depth(desktop_color_depth());
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, w, h, 0, 0);

    switch_fullscreen();

    line(screen, 0, 0, w - 1, h - 1, makecol(255, 255, 255));

    while (readkey() >> 8 != KEY_ESC);
    return 0;
}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/