Hi,

On Wed, 2005-07-27 at 23:28 +0200, Oliver Kutter wrote:
Hi,
>
> I have a problem with OpenSG and its threads. In my program, I want to
> load many images in an array during the rendering in the background with
> a thread. That works fine, the images are loaded into the array and when
> I want to get the images, I get them without any problems. But, when I
> want to get the images after the thread has finished, I get a
> segmentation fault. Why? The images and its data were there before.
>
> Here is the important part of my code:
>
> // --------------------
>
> // this is the function my thread calls
> void threadFunc (void *args) {
>     // this call loads the images into the array
>     for (int i=0; i<imageNum; i++) ((DataProcessing *)
> args)->loadDataImage(i);
>
>     // when I call here this function, everything is fine (it prints the
> data of the image into the shell)
>     for (int i=0; i<imageNum; i++) ((DataProcessing *) args)->printData(i);
> }
>
> [ ... ]
>
> // Then in the class DataProcessing
>
> void DataProcessing::updateImages() {
>
>     // when I call here loadDataImage(i), everything is fine and I can
> get the images and its data later,
>     // but that take a long time and during that loading, no more
> rendering is done.
>     // for (int i=0; i<imageNum; i++) loadDataImage(i);
>
>     // this is, where the thread is important
>     // the thread
>     Thread *pThread = dynamic_cast<Thread
> *>(ThreadManager::the()->getThread("LoadDataImageThread"));
>
>     // As a parameter I give a pointer of this object to call the object
> functions in the threadFunc.
>     pThread->runFunction(threadFunc, 1, (void *) this);
>                                        ^^

this looks like your loader is running using aspect 1

>
>     // much later in the program
>     // but when I want to get access to the images (much later, when the
> thread has finished), I get a segmentation fault.
>     for (int i=0; i<imageNum; i++) printData(i);
>

my guess would be that these calls are using a different aspect
must likely 0.

So you either can sync the changes from aspect 1 back to the aspect you
are calling printData for or, if the image loader does not touch
anything the main thread is using, run the loading thread using
the same aspect as the printData thread.

regards,
  gerrit




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to