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

Justin Rosen jmylesrosen at gmail.com
Sun Apr 29 17:43:01 EDT 2012


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] << ">"
>>> << endl;
>>>       cout << "Focal: <" << focal[0] << ", " << focal[1] << ", " <<
>>> focal[2] << ">" << endl;
>>>       cout << "Pos: <" << pos[0] << ", " << pos[1] << ", " << pos[2] <<
>>> ">" << endl;
>>>
>>>       double planes[24];
>>>       camera->GetFrustumPlanes(1, planes);
>>>
>>>       for (int i=0; i < 6; i++){
>>>         cout << planes[(i*4)] << "x + " << planes[(i*4)+1] << "y + " <<
>>> planes[(i*4)+2] << "z + " << planes[(i*4)+3] << endl;
>>>       }
>>>     }
>>>   }
>>> }
>>>
>>> int
>>> main (int argc, char* argv[])
>>> {
>>>   vtkSmartPointer<vtkRenderer> renderer =
>>> vtkSmartPointer<vtkRenderer>::New ();
>>>   vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New
>>> ();
>>>   vtkSmartPointer<vtkRenderWindow> window =
>>> vtkSmartPointer<vtkRenderWindow>::New ();
>>>
>>>   window->AddRenderer (renderer);
>>>   window->SetSize (500, 500);
>>>   interactor->SetRenderWindow (window);
>>>
>>>   interactor->Initialize();
>>>
>>>   boost::thread workerThread(workerFunc, renderer->GetActiveCamera());
>>>
>>>   window->Render ();
>>>
>>>   vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
>>> vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New ();
>>>   interactor->SetInteractorStyle (style);
>>>
>>>   interactor->Start ();
>>>
>>>   return 0;
>>> }
>>>
>>>
>>> Thanks!
>>> Justin
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120429/bc97367e/attachment.htm>


More information about the vtkusers mailing list