Nevermind, bunch of print statements must of been slowing things down, it still crashes immediately without any print statements :(<div><br><div class="gmail_quote">On Sun, Apr 29, 2012 at 2:38 PM, Justin Rosen <span dir="ltr"><<a href="mailto:jmylesrosen@gmail.com" target="_blank">jmylesrosen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Grabbing a copy of the camera in a separate thread seems to do the trick.  Can anyone shed some light onto this topic?</div>
<div>
<p>vtkCamera<span> *camera = </span>vtkCamera<span>::</span><span>New</span><span>();<br></span>camera-><span>ShallowCopy</span>(renderer-><span>GetActiveCamera</span>());</p>
<p>Thanks,<br>Justin</p></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote">On Sat, Apr 28, 2012 at 9:52 PM, Justin Rosen <span dir="ltr"><<a href="mailto:jmylesrosen@gmail.com" target="_blank">jmylesrosen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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.<div>
<br></div><div>Thanks,</div><div>Justin</div><div><div><div><div><br><div class="gmail_quote">On Sat, Apr 28, 2012 at 3:23 PM, Justin Rosen <span dir="ltr"><<a href="mailto:jmylesrosen@gmail.com" target="_blank">jmylesrosen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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><span><font color="#888888"><div>Justin</div>
</font></span></blockquote></div><br></div></div>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br></div>