Hi,
I'm not sure to understand who works the thread and aspects, you sayed that when you merge the changelist it does not aplly the modifcation made by the thread on the scene graph, that :

It only records the changes done on some aspect so they can be
applied together with the changes done in the current threads aspect


So when are really comitted this changes?

Anyway I try to protect the rendering as you said like this :

   void Display( void )
             GTLock->aquire();
Thread::getCurrentChangeList()->merge(*(GT->getChangeList()));
             GT->getChangeList()->clearAll();
             bsManager->render() ;
             Thread::getCurrentChangeList()->clearAll() ;

             GTLock->release();

             glClear(GL_COLOR_BUFFER_BIT) ;
             glutSwapBuffers() ;
   }

And here is the function executed by the thread :

   void  GrimageThread( void* args){
     while (true) {
NodePtr N = G->createGeometry(); if (N != NullFC) {
           GTLock->aquire();
G->setGeometry(N); GTLock->release();
      }
       usleep(1);
     }
   }

And it still crash after about 40 seconds, during these 40 seconds it works fine,
the geometry is corectly updated. Here is the crash message :

   LPS (grimage thread): 56.2468
   LPS (client): 101.825
   WARNING:  Can't find container id:7942
   WARNING:  Can't find container id:7942
   WARNINGWARNING:  Can't find container id:: 7942 Can't find container
   id:7942

   WARNING:  recurse: core is Null,  don't know what to do!
   WARNING:  recurse: core is Null,  don't know what to do!
   WARNING:  recurse: core is Null,  don't know what to do!
   WARNING:  recurse: core is Null,  don't know what to do!
   LPS (client): 107.132
   LPS (grimage thread): 59.7129
   LPS (client): 98.8006
   LPS (client): 107.331
   WARNING:  Can't find container id:8065
   WARNING:  Can't find container id:8065
   WARNING:  Can't find container id:8065
   WARNING:  Can't find container id:8065
   terminate called after throwing an instance of
   'osg::BinaryDataHandler::ReadError'
     what():  BinaryDataHandler ReadError: Channel closed


I don't have any idea how it's possible as I lock the setGeometry function in the thread, and the ChangeList apply and the rendering function
in the display() func.

However if, like I said before, I call createGeometry() inside the Lock everything works well :

   void  GrimageThread( void* args){
     while (true) {
           GTLock->aquire();
NodePtr N = G->createGeometry(); G->setGeometry(N); GTLock->release();
           usleep(1);
    }
   }


It's strange because the create geometry function only uses with local variables, that the function creates, and have absolutely no actions on the scenegraph, it just create a new node, not connected to anyother one, so why should it be include in
the mutex?


Carsten Neumann wrote:
        Hello Adrien,

Adrien wrote:
Hi,
I've some problem with OpenSG thread,
In my main function I create 3 node, a geometry
node, attach to the material group node, attach to
the transformation node.
At that point no problem, my object corectly appear in the scene.

    void  GrimageThread( void* args)
    {
      while (true) {

NodePtr N = G->createGeometry(); GTLock->aquire();
        G->setGeometry(N);
        GTLock->release();
usleep(1); // let the display loop acquire the mutex
      }
    }

And the last thing is to apply the thread change list in the display function :

          GTLock->aquire();
          Thread::getCurrentChangeList()->merge(*(GT->getChangeList()));
          GT->getChangeList()->clearAll();
          GTLock->release();

Merging the changelist does not apply the changes from it to the current
aspect. It only records the changes done on some aspect so they can be
applied together with the changes done in the current threads aspect.
Please note that I'm talking about aspects not threads these are
different concepts and OpenSG is mainly concerned with aspects (you can
read about these things here:
<http://opensg.vrsource.org/trac/wiki/Tutorial/OpenSG1/Multithreading>

You should position your locks in such a way that the setGeometry call
and rendering of the scene are mutually exclusive operations. I think
this is what crashes you here: The main thread renders the scene (but
does not hold the GTLock), the GT thread acquires the lock and sets the
geo while the rendering is in progress. The old geometry dies while it
still is queued for rendering.

        Hope it helps,
                Carsten

Unfortunately this work a few second, where I can see my object "moving", wich means the geometry is correctly
updated, but after some time it segfault.
This problem come from the geometry. If I don't add my object to the scene root node but still update it no segfault . And if I add it, but if in the GrimageThread() function I call createGeometry() between the Lock aquires() and release() it also works. But it that case there is not point to use a thread as the display() loop have to wait
the calcul of the new geometry to aquire the Lock and aplly the change list.

So why is there problems? If the main processus interupt the creation of the geometry launched by the thread it's not a problem, as we are working on local objects not part of the scene graph, when the traead will get the processor again it will continue to construct the geometry. We only want that he is not interupted when he will update the scene graph
by removing the old node and adding the new one.

Does anyone know where this problem comes from?

Thanks,
Adrien




------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


------------------------------------------------------------------------

_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to