Results 1 to 17 of 17

Thread: X error when creating main window

  1. #1

    Default X error when creating main window

    Hello,

    I've just compiled and installed ClanLib v2.2.4 on my laptop's Gentoo.
    Graphic chipset: nVidia Corporation Quadro NVS 135M (rev a1)
    Nvidia drivers: 256.53
    Xorg : 1.7.7

    I cannot run any samples provided.
    I tried several (GUI, 2d ...) and i got always the same error:

    Code:
    ~/ClanLib-2.2.4/Examples/Display_Text/Text/Sources$ ./a.out 
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  42 (X_SetInputFocus)
      Serial number of failed request:  56
      Current serial number in output stream:  57
    A "blank" window appears, and then I have no choice but killing the app with ctrl+c.

    Sometimes (very seldom), the app runs correctly.

    I've googled the error, and it appears to be a synchronisation problem.
    I tried to put "sleep(1)" between steps of window creation, but no changes happened.

    I also tried to debug the code, for having longer delay between each step, with no luck either.

    I've tried ClanLib on my desktop computer (Linux) and on another desktop (MS-Windows XP) and it works (with version 2.2.3).

    A problem with 2.2.4 version ? I did a search on this forum, the problem has already raised once, but the code involved seems to have changed lot. I did not found the "XSync" the thread's talking about.

    Any clue ?

    Thank you.

    EDIT : if i load the machine with a command like this:

    Code:
    while [ 1 ]; do echo; done
    (about 70% of cpu occupation)

    the examples always run. So it appears to be a timing problem, with probably a function inside ClanLib libraries which doesn't wait another to be ready/initialised. Probably, it's a sleeping bug which occur rarely under specific conditions. Feel free to ask me for helping tracking it down.

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Nothing has changed in the X setup in any target. (from 2.2.3 to 2.2.4)

    Look at which targets work in the DisplayTarget example

    The X setup should be perfect, I can't understand what is wrong.

    If I have time later, i'll try installing Gentoo
    Last edited by rombust; 10-11-2010 at 06:55 AM.

  3. #3

    Default

    Quote Originally Posted by rombust View Post

    Look at which targets work in the DisplayTarget example
    DisplayTarget won't even start on my laptop.
    I can see a window which begin to appears, and then it's destroyed immediatly.
    The program exits with:

    Code:
     
    ~/sources/ClanLib-2.2.4/Examples/Display/DisplayTarget$ ./displaytarget 
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  42 (X_SetInputFocus)
      Serial number of failed request:  97
      Current serial number in output stream:  98
    I'll investigate more tomorrow.
    As yesterday, the program runs perfectly with a hogged cpu.

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    That's interesting.

    It means that the problem is with the X server, not opengl. The DisplayTarget initial window uses a software renderer using XLib.

    Which window manager are you using? gnome, kde ...

  5. #5

    Default

    My window manager is Fluxbox. I don't use desktop environment like Gnome or KDE.
    (though i have some Gnome libraries for programs which won't run without them).

    Here is a minimalist program, which always hang (with the same Xlib error as before).

    Code:
    #include <ClanLib/core.h>
    #include <ClanLib/display.h>
    #include <ClanLib/swrender.h>
    #include <ClanLib/gl.h>
    
    int main(void)
    {
      CL_SetupCore setup_core;
      CL_SetupDisplay setup_display;
      CL_SetupSWRender setup_swrender;
    //  CL_SetupGL setup_opengl; //doesn't work either
      CL_DisplayWindow window("ClanLib", 640, 480);
      return 0;
    }

    Code:
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  42 (X_SetInputFocus)
    For the moment, it doesn't help much. But as i get same error as before, it will be easier for isolating the problem.

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    This function is at fault:

    Code:
    void CL_X11Window::set_enabled(bool enable)
    {
    	if (enable)
    	{
    		if (!has_focus())
    			XSetInputFocus(disp, window, RevertToNone, CurrentTime);
    	}else
    	{
    		if (has_focus())
    			XSetInputFocus(disp, window_last_focus, window_last_revert_return, CurrentTime);
    	}
    }
    If you disable this function. It works.

    The function looks dubious, it assumes window_last_focus still exists.

    I think this function is broken I don't understand why it is even calling XSetInputFocus and
    not an XLib window enable/disable function (if one exists)

  7. #7
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    The set_enabled(bool enable) on windows does the following:

    (Quote from: http://msdn.microsoft.com/en-us/libr...91(VS.85).aspx "EnableWindow Function" )

    Enables or disables mouse and keyboard input to the specified window or control. When input is disabled, the window does not receive input such as mouse clicks and key presses. When input is enabled, the window receives all input.
    So, on linux I tried to emulate it by using XSetInputFocus.

    I think this causes more problems than it fixes.

    Ideally the X window manager should control the input focus. You should never change it without annoying users.

    However within an application, you may want to do this.

    At the moment, I think it gets it wrong.

    I am not sure why it does not work on Fluxbox, but I guess it is because, although the window is mapped, it is not displayed on the screen.

    To fix that, sleep(100) might work, but that's very nasty. The delay value depends on the PC's speed.

    Maybe we can wait for a "window repaint request" instead.

    We need an Xlib export, I wonder if there are any forums or IRC channels out there.

    Anyway, if all the examples and Carambola Chat works on Linux, I guess it's safe to simply disable the set_enabled() function.

  8. #8

    Default

    Hello,

    so after our chat on irc, i did the modifications you've suggested in CL_X11Window::create_new_window

    Code:
    	if (desc.is_visible())
    	{
             //  show(true);
    		show(false);
    	//   set_enabled(true);
    	}
           fprintf(stderr,"I was in create_new_window\n"); //just to be sure :)
    I've tried with "DisplayTarget" example.

    I got same error:

    Code:
    ~/sources/ClanLib_debug/Examples/Display/DisplayTarget$ ./displaytarget
    I was in create_new_window
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  42 (X_SetInputFocus)
      Serial number of failed request:  97
      Current serial number in output stream:  98
    So the Xlib error seems to occur after window creation, doesn't it ?

  9. #9
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default



    It works here in fluxbox.

    I have applied the patch to svn.

    It is strange that you are still getting X_SetInputFocus errors even when XSetInputFocus is never called.

  10. #10

    Default

    Quote Originally Posted by rombust View Post
    It is strange that you are still getting X_SetInputFocus errors even when XSetInputFocus is never called.
    I put a "fprintf" on the last line of create_new_window.

    Code:
       (...)
    
    	if (desc.is_fullscreen()) set_fullscreen();
    
    	XSync(disp, True);
       fprintf(stderr,"Quitting create_new_window\n");
    
    }

    When running, i get:

    Code:
    Quitting create_new_window
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  42 (X_SetInputFocus)
      Serial number of failed request:  97
      Current serial number in output stream:  98

    I think error is raising after window creation. So (ok, that's not an option, it was just for trying) i commented entire "set_enabled" function. So, no more XSetInputFocus call. No call, no problem

    It works with the few examples i've tried later.

    I don't know Xlib, i'll try and ask to a friend.

  11. #11
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Can you name an example that it did not work on?

    I tried Basic2D and the GUI example and it worked.

    I guess that an example is calling CL_DisplayWindow's set_enabled() which does not work.

  12. #12

    Default

    (finally i've managed to get it work, after having writing a bunch of text and doing a lot of tests.. i left my experiments here, so you can add your own comments )



    Quote Originally Posted by rombust View Post

    Can you name an example that it did not work on?
    All the examples are not working, so for next try, i will stick with "Basic2D" as you tested it with success.




    I guess that an example is calling CL_DisplayWindow's set_enabled() which does not work.
    Here is what i did.
    I began to put Xlib in synchronous mode, for forcing Xlib to sequential execution (otherwise, Xlib orders are delayed, and you can think that a call was succesful, as you get error message later in execution flow).

    For enabling synchronous mode, i put in Program::main function of file program.cpp (in Sources of Basic2D)

    Code:
    int Program::main(const std::vector<CL_String> &args)
    {
      _Xdebug=1; //Xlib now in synchronous mode
      ...
    In x11_window.cpp, all the calls to CL_X11Window::set_enabled are done like this (for example, with "hide()")

    Code:
    void CL_X11Window::hide()
    {
    fprintf(stderr,"enter: %s (%d)\n",__FUNCTION__,__LINE__);
    	set_enabled(false);
    fprintf(stderr,"quit: %s (%d)\n",__FUNCTION__,__LINE__);
    	XUnmapWindow(disp, window);
    }

    CL_X11Window::show use same rule, only with added display of "activate" boolean.

    Code:
    fprintf(stderr,"enter: %s (%d) (activate:%s)\n",__FUNCTION__,__LINE__,activate?"true":"false");
       if (activate) set_enabled(true);
    fprintf(stderr,"quit: %s (%d)\n",__FUNCTION__,__LINE__);

    couple enter/quit shows that the call was ok (and we are sure of this, because Xlib is in synchronous mode).

    In CL_X11Window::create_new_window (file x11_window.cpp, i did what you said:

    Code:
    	// make window visible:
    	if (desc.is_visible())
    	{
    #define modif     //will not show if defined
    #ifdef modif     
    	 show(false);  //debug setting
    #else	
        show(true);  //normal setting
        fprintf(stderr,"enter: %s (%d)\n",__FUNCTION__,__LINE__);
        set_enabled(true);
        fprintf(stderr,"quit: %s (%d)\n",__FUNCTION__,__LINE__);
    #endif
    	}

    Finally, i launch Basic2D example.

    Code:
    ~/sources/ClanLib_debug/Examples/Display/Basic2D$ ./basic2d 
    enter: show (360) (activate:false)
    quit: show (362)
    Quitting create_new_window
    Holy Mother of God, it works.
    I can't believe it.

    I think that it wasn't working before, because i did not recompile example after having recompiled "display" part of ClanLib.
    I thought that i had only to put the new files in lib directory, and relaunch example.
    (i still don't understand why i have to recompile the example, after modifying the library and put in the library directory).

    Thank you for the help, i will wait the next release of ClanLib, and i'll recompile sources with "official" modifications.


    EDIT : i've tried a lot of examples, all seems to work except Examples/GUI/GUILayout (same error as before)
    I will try to find later where the second call to set_enabled is.
    Last edited by texhel; 10-16-2010 at 06:06 AM.

  13. #13
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    The second call is in the GUILayout example to the clanGUI component

    Code:
    window.set_visible(true);
    Because of default paremters, this function is actually

    Code:
    window.set_visible(true, true);
    The second parameter is a flag that calls set_enabled() (indirectly via display window.show() )

    Yes, that could be set to false, but there is still a problem with set_enabled() that should be fixed.

    My guess is that the problem is in here:

    Code:
    void CL_X11Window::show(bool activate)
    {
    	XMapWindow(disp, window);
    	wait_mapped();
    	clear_structurenotify_events();
    	if (activate) set_enabled(true);
    
    	// Force the window is updated
    	CL_Rect window_rect = get_viewport();
    	set_size(window_rect.get_width(), window_rect.get_height(), true);
    }
    The wait_mapped() function "should" ensure the window is mapped correctly, so set_enabled() works.

    It does on KDE and Gnome. My guess that either wait_mapped() has a bug, or something is wrong for fluxbox.

  14. #14

    Default

    Quote Originally Posted by rombust View Post

    The wait_mapped() function "should" ensure the window is mapped correctly, so set_enabled() works.

    It does on KDE and Gnome. My guess that either wait_mapped() has a bug, or something is wrong for fluxbox.
    It could be a problem with Fluxbox, but i got another computer with Gentoo+Fluxbox on it. ClanLib runs on it without problems.

    I've done some tries with wait_mapped().
    I tried to flush Xlib queue after the "MapNotify" event waiting, with no improvement.
    I tried lots of others things, as i don't know of xlib works, it was useless.
    I did lot of search for finding how we can know that the window is mapped, but it seems to be straightforward: waiting "MapNotify" and that's all. Nobody even ask, so it's trivial i guess.

    The only thing which seems to work is putting usleep(1000) after the XMaskEvent loop of wait_mapped.
    But it's not a solution. I left this one in my own lib, hope someone would know something better than this ugly hack

  15. #15
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    After a discussion on IRC.

    Window's version of set_enabled() calls EnableWindow() which tells the windows API that the window can have input focus if desired.

    Linux version of set_enabled() is incorrect, it should not set the input focus.

    For now it will be best to have set_enabled() as a empty function.

    If anyone does require require disabling input focus on a window, the function can be fixed by changing the event masks.
    Code:
    		KeyPressMask |
    		KeyReleaseMask |
    		ButtonPressMask |
    		ButtonReleaseMask |
    I am not sure how this is done

  16. #16
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    set_enabled() has now been disabled.

    Thanks for finding this bug.

  17. #17

    Default

    Quote Originally Posted by rombust View Post
    set_enabled() has now been disabled.
    Thank you, and thank to the friendly people of #clanlib.

    Now i just have to read all the documentation for learning how to use ClanLib.
    Piece of cake (or not)

Similar Threads

  1. CL_CommandLine with Cross-platform application main
    By russ_allegro in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 05-05-2010, 10:59 PM
  2. How to : Delete/Close a Window and Center a Window ?
    By Fr3DBr in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 08-24-2009, 02:55 AM
  3. Error&Workaround: Unable to create OpenGL creation query window
    By McBen in forum Official ClanLib SDK Forums
    Replies: 3
    Last Post: 04-08-2009, 05:41 PM
  4. Main Developer ?
    By zyklo in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 08-21-2008, 03:00 AM
  5. error in custom pallette window...
    By harrio in forum Novashell Game Creation System
    Replies: 1
    Last Post: 04-06-2008, 01:16 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •