Re: XForms: Some news about threads and Xforms and OpenGL...

From: Nicolas Castagne (Nicolas.Castagne@imag.fr)
Date: Thu Mar 13 2003 - 05:46:09 EST

  • Next message: Steve Lamont: "Re: XForms: Some news about threads and Xforms and OpenGL..."

    # To subscribers of the xforms list from Nicolas Castagne <Nicolas.Castagne@imag.fr> :

            Uh... Seems you are wrong Steve... I should have given more
    precisions in my mail yesterday.

            The point is that the context seems to be activated within the
    form library itself, before calling the Expose handler (may because of a
    call to fl_activate_glcanvas() ). As a consequence, a very simple Expose
    handler will break the program - even though its only work is to print
    somethin on the stdout output.

            My problem is then to take care of Expose events on the
    canvas without using canvas handler. I experimented various solutions -
    see my last post. The solution I use today is to declare a post handler on
    the canvas and catch FL_DRAW events. However, the behavior of such a
    solution is not totally correc : the FL_DRAW event is not always
    generated - see my last post again.
     

            Second point : according to GL man pages, it seems that a context
    cannot be shared beetween threads. Consequence : it would not be
    possible to activate a context in a thread that did not create it, even
    though you take care to avoid simulteous activations.

            As a consequence, an Expose event catched by the main program
    cannot handle itself the expose. It needs to ask the thread to do so. The
    program I posted yesterday proposes a very-very simple solution to this
    problem (through the int ExposeEvent communication variable). This
    solution is not the best, of course (I use semaphores in a different one
    much more efficient), but it behaves correctly.

            
            As a conclusion, my two main questions is :
            How could I detect Expose event on the canvas without using a
    canvas handler ?
            If it is not possible, do I need to give a close look to the
    XForms sources - to ovoid the activation of the canvas before calling the
    expose handler ?

            Thx !

            NC

            
    --------------------------------------------------------------------
    Nicolas Castagne

    Laboratoire Informatique et Creation Artistique
    Association pour la Creation et la Recherche
                    sur les Outils d'Expression
    INPG, 46 av Felix Viallet
    38 000 Grenoble, France

    tel : (33) 4 76 57 46 60
    --------------------------------------------------------------------

    - Certains hommes parlent durant leur sommeil.
    - Il n'y a guere que les conferenciers pour parler
    - pendant le sommeil des autres.
    Alfred Camus

    On Wed, 12 Mar 2003, Steve Lamont wrote:

    > # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
    >
    > > When a handler is added to handle expose events, the Xlib
    > > sometimes generates GLX bad access errors ("attempt to acces private
    > > ressource denied" - request X_GLXMakeCurrent) - and the program aborts.
    > > It seems that handler for expose event cannot be added to a canvas
    > > "possessed" by a thread.
    >
    > This is mostly an OpenGL problem.
    >
    > Basically, only one thread may own the GLXContext at any one time. If
    > multiple threads try to access the same GLXContext simultaneously,
    > disaster ensues.
    >
    > If you *must* access the context from multiple threads, you must
    > bracket the critical with mutexes or somethign similar and be careful to
    > release the context before exiting the critical section, as per the
    > manual page for glXMakeCurrent():
    >
    > To release the current context without assigning a new one, call
    > glXMakeCurrent with drawable set None and ctx set to NULL.
    >
    > Since the event handler callback is invoked from the main thread
    > (defined as the one that call fl_do_forms() or its ilk), it is likely
    > to tromp on any other threads which might try to draw to the canvas.
    >
    > For example:
    >
    > pthread_mutex_lock( &mutex ); /* Grabs the mutex when available */
    >
    > /* Grab the context */
    >
    > glXMakeCurrent( fl_get_display(), FL_ObjWin( canvas ), context );
    >
    > /* [do your GL stuff here] */
    >
    > /* Free the context */
    >
    > glXMakeCurrent( fl_get_display(), None, NULL );
    >
    > pthread_mutex_unlock( &mutex ); /* Hands the mutex back */
    >
    > spl
    >
    >
    > _________________________________________________
    > To unsubscribe, send the message "unsubscribe" to
    > xforms-request@bob.usuhs.mil or see
    > http://bob.usuhs.mil/mailserv/xforms.html
    > XForms Home Page: http://world.std.com/~xforms
    > List Archive: http://bob.usuhs.mil/mailserv/list-archives/
    >
    >

    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Thu Mar 13 2003 - 05:43:25 EST