[vtkusers] vtkCamera->GetFrustumPlanes segfault from a boost thread

Justin Rosen jmylesrosen at gmail.com
Wed May 9 19:26:36 EDT 2012


Thanks for the reply!

Thats basically the conclusion I came too. My plan is to acquire the scene
data in the main thread, then pass this on to any background worker thread.

Will I run into the same issues with modifying a collection of actors?  My
intent is to have a collection of polydata objects updated in the
background that are streamed into the viewer.  Do you think I'll hav issues
with this?

Thanks
Justin

On Wednesday, May 9, 2012, Marcus D. Hanwell wrote:

> The VTK rendering classes are not thread safe, and we do not
> initialize OpenGL to render in a thread safe fashion. There are
> several methods that are likely to cause issues if called from
> multiple threads.
>
> You could communicate across threads but restrict the VTK calls to the
> main thread.
>
> Marcus
>
> On Sun, Apr 29, 2012 at 5:43 PM, Justin Rosen <jmylesrosen at gmail.com>
> wrote:
> > Nevermind, bunch of print statements must of been slowing things down, it
> > still crashes immediately without any print statements :(
> >
> > On Sun, Apr 29, 2012 at 2:38 PM, Justin Rosen <jmylesrosen at gmail.com>
> wrote:
> >>
> >> Grabbing a copy of the camera in a separate thread seems to do the
> trick.
> >>  Can anyone shed some light onto this topic?
> >>
> >> vtkCamera *camera = vtkCamera::New();
> >> camera->ShallowCopy(renderer->GetActiveCamera());
> >>
> >> Thanks,
> >> Justin
> >>
> >>
> >> On Sat, Apr 28, 2012 at 9:52 PM, Justin Rosen <jmylesrosen at gmail.com>
> >> wrote:
> >>>
> >>> It looks like vtkCamera->GetFrustumPlanes isn't thread safe?  It makes
> >>> quite a few changes to some of the it's member variables.  I tried
> adding a
> >>> mutex lock between vtkCommand::Start/EndEvent, but I'm still seg
> faulting.
> >>>
> >>> Thanks,
> >>> Justin
> >>>
> >>> On Sat, Apr 28, 2012 at 3:23 PM, Justin Rosen <jmylesrosen at gmail.com>
> >>> wrote:
> >>>>
> >>>> If anyone one knows a bit about using vtk and boost threads I'd really
> >>>> appreciate the help.  I'm fairly new to vtk and threads in general
> and I'm
> >>>> trying to figure out why calling vtkCamera->GetFrustumPlanes from a
> boost
> >>>> thread eventually segfaults.  It takes quite a few of iterations
> before the
> >>>> segfault occurs.
> >>>>
> >>>> The general idea is that I have main application UI and a worker
> thread
> >>>> in the background which'll be doing some processing (Eventually
> >>>> updating/modifying a list of actors).  At the moment I'm just trying
> to get
> >>>> the cameras view frustum...
> >>>>
> >>>> If I remove the call to camera->GetFrustumPlanes the application runs
> >>>> without seg faulting.  Any idea what I may be doing wrong?
> >>>>
> >>>> void workerFunc(vtkCamera *camera)
> >>>> {
> >>>>   double prevUp[3] = {0, 0, 0};
> >>>>   double prevFocal[3] = {0, 0, 0};
> >>>>   double prevPos[3] = {0, 0, 0};
> >>>>
> >>>>   while(true){
> >>>>     double *up = camera->GetViewUp();
> >>>>     double *focal = camera->GetFocalPoint();
> >>>>     double *pos = camera->GetPosition();
> >>>>
> >>>>     bool viewpointChanged = false;
> >>>>
> >>>>     // Check up vector
> >>>>     if(up[0] != prevUp[0] || up[1] != prevUp[1] || up[2] != prevUp[2])
> >>>>       viewpointChanged = true;
> >>>>
> >>>>     // Check focal point
> >>>>     if(focal[0] != prevFocal[0] || focal[1] != prevFocal[1] ||
> focal[2]
> >>>> != prevFocal[2])
> >>>>       viewpointChanged = true;
> >>>>
> >>>>     // Check position
> >>>>     if(pos[0] != prevPos[0] || pos[1] != prevPos[1] || pos[2] !=
> >>>> prevPos[2])
> >>>>       viewpointChanged = true;
> >>>>
> >>>>     // If the viewpoints changed get the cameras frustum
> >>>>     if (viewpointChanged){
> >>>>       prevUp[0] = up[0]; prevUp[1] = up[1]; prevUp[2] = up[2];
> >>>>       prevFocal[0] = focal[0]; prevFocal[1] = focal[1]; prevFocal[2] =
> >>>> focal[2];
> >>>>       prevPos[0] = pos[0]; prevPos[1] = pos[1]; prevPos[2] = pos[2];
> >>>>
> >>>>       cout << "View Changed" << endl;
> >>>>       cout << "Up: <" << up[0] << ", " << up[1] << ", " << up[2] <<
> ">"
> >>> _______________________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the VTK FAQ at:
> > http://www.vtk.org/Wiki/VTK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120509/bf44efbd/attachment.htm>


More information about the vtkusers mailing list