[vtkusers] vtkCamera->GetFrustumPlanes segfault from a boost thread
Marcus D. Hanwell
marcus.hanwell at kitware.com
Wed May 9 11:09:52 EDT 2012
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] << ">"
>>>> << 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
>>>
>>>
>>
>
>
> _______________________________________________
> 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
>
More information about the vtkusers
mailing list