<div>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.</div>
<div><br></div><div>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...<div>
<div><br></div><div>If I remove the call to camera->GetFrustumPlanes the application runs without seg faulting. Any idea what I may be doing wrong?<br><br><div>void workerFunc(vtkCamera *camera)</div><div>{</div><div>
double prevUp[3] = {0, 0, 0};</div><div> double prevFocal[3] = {0, 0, 0};</div><div> double prevPos[3] = {0, 0, 0};</div><div> </div><div> while(true){</div><div> double *up = camera->GetViewUp();</div><div> double *focal = camera->GetFocalPoint();</div>
<div> double *pos = camera->GetPosition();</div><div><br></div><div> bool viewpointChanged = false;</div><div><br></div><div> // Check up vector</div><div> if(up[0] != prevUp[0] || up[1] != prevUp[1] || up[2] != prevUp[2])</div>
<div> viewpointChanged = true;</div><div><br></div><div> // Check focal point</div><div> if(focal[0] != prevFocal[0] || focal[1] != prevFocal[1] || focal[2] != prevFocal[2])</div><div> viewpointChanged = true;</div>
<div><br></div><div> // Check position</div><div> if(pos[0] != prevPos[0] || pos[1] != prevPos[1] || pos[2] != prevPos[2])</div><div> viewpointChanged = true;</div><div><br></div><div> // If the viewpoints changed get the cameras frustum</div>
<div> if (viewpointChanged){</div><div> prevUp[0] = up[0]; prevUp[1] = up[1]; prevUp[2] = up[2];</div><div> prevFocal[0] = focal[0]; prevFocal[1] = focal[1]; prevFocal[2] = focal[2];</div><div> prevPos[0] = pos[0]; prevPos[1] = pos[1]; prevPos[2] = pos[2];</div>
<div><br></div><div> cout << "View Changed" << endl;</div><div> cout << "Up: <" << up[0] << ", " << up[1] << ", " << up[2] << ">" << endl;</div>
<div> cout << "Focal: <" << focal[0] << ", " << focal[1] << ", " << focal[2] << ">" << endl;</div><div> cout << "Pos: <" << pos[0] << ", " << pos[1] << ", " << pos[2] << ">" << endl;</div>
<div><br></div><div> double planes[24];</div><div> camera->GetFrustumPlanes(1, planes);</div><div><div><br></div><div> for (int i=0; i < 6; i++){</div><div> cout << planes[(i*4)] << "x + " << planes[(i*4)+1] << "y + " << planes[(i*4)+2] << "z + " << planes[(i*4)+3] << endl;</div>
<div> }</div></div><div> }</div><div> }</div><div>}</div><div><br></div><div>int</div><div>main (int argc, char* argv[])</div><div>{</div><div> vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New ();</div>
<div> vtkRenderWindowInteractor *interactor = vtkRenderWindowInteractor::New ();</div><div> vtkSmartPointer<vtkRenderWindow> window = vtkSmartPointer<vtkRenderWindow>::New ();</div><div><br></div><div> window->AddRenderer (renderer);</div>
<div> window->SetSize (500, 500);</div><div> interactor->SetRenderWindow (window);</div><div><br></div><div> interactor->Initialize();</div><div><br></div><div> boost::thread workerThread(workerFunc, renderer->GetActiveCamera());</div>
<div><br></div><div> window->Render ();</div><div><br></div><div> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New ();</div><div> interactor->SetInteractorStyle (style);</div>
<div><br></div><div> interactor->Start ();</div><div><br></div><div> return 0;</div><div>}</div></div></div></div><div><br></div><div><br></div><div>Thanks!</div><div>Justin</div>