[vtkusers] User-defined ExitMethod to close an interactive vtk model by breaking threads to vtkRenderWindowInteractor and vtkRenderWindow gives Segmentation Fault

Anwar Upal upal at me.queensu.ca
Mon Nov 19 09:54:40 EST 2001


Dear All:

My MSc project involves describing the relative motions between bones in 
the wrist, given 3D reconstructed scans of the same wrist in more than one 
posture. I am using VTK for this purpose.  I am using another library V for 
designing my graphical user interface (gui).

My gui gives control to vtk to render the 3D images of the wrist in a 
vtkRenderWindow and starts the vtkRenderWindowInteractor.   When the user 
wants to close the 3D vtk model, stop the vtkRenderWindowInteractor, kill 
the vtkRenderWindow and come back to the gui for further computation, I 
experience a problem.

vtkRenderWindowInteractor's default exitMethod kills my application and gui 
as well as the vtkRenderWindow.  We defined a user-defined exitMethod to 
give control back to program by terminating the threads to 
vtkRenderWindowInteractor and vtkRenderWindow.  This gives me a 
segmentation fault when my exitMethod tries to break the threads.  Is there 
another way...?

I will show the relevant code below.  My program has a carpus class.  This 
class has a method called carpalRender for rendering the carpus.  And a new 
user-defined exitMethod to exit the vtk window opened by carpalRender.

class carpus
{
private:

   //I define these as members of carpus so that I can terminate the 
threads from my exit method

   vtkRenderWindowInteractor *iren;
   vtkRenderWindow* renWindow;
   vtkRenderer* scene_render;
   ...

public:
   //render to show itself
   void carpalRender(...);

   //new exit method for vtkWindowInteractor so it does not terminate 
application
   void carpus::MemberExitMethod(void *arg);
   ...
};

Now Here is the relevant code from the method carpus::carpalRender which 
calls the ExitMethod.

void carpus::carpalRender(...)
{
   ...
   renWindow = vtkRenderWindow::New();
   ...

   // Create window interactor
   iren = vtkRenderWindowInteractor::New();
   ...

   // set the user-defined C-style ExitMethod as the new exit method
   iren->SetExitMethod (ExitMethod,NULL);

   // Draw the resulting scene
   renWindow->Render();

   // Enable mouse interaction
   iren->Start();

   //since vtkRenderWindowInteractor does not give control back to 
carpalRender
   //any further code in carpalRender would not get executed
};

Now the following segment of code is the C-style exit method which then 
executes another MemberExitMethod which is a member of the carpus class.

//*********************>>> ExitMethod <<<<************************//
   void ExitMethod(void *arg)
   {
     static_cast<carpus*>(arg)->MemberExitMethod(arg);
   };

//*********************>>> carpus::MemberExitMethod 
<<<<************************//
   void carpus::MemberExitMethod(void *arg)
   {
     iren->Delete();
     renWindow->Delete();
  };

Any ideas are welcome.  Thanks,
Anwar Upal



 >hi,
 >
 >>>>> "Bill" == William A Hoffman <billlist at nycap.rr.com> writes:
 >
 >    Bill> VTK callback functions are all C functions and can not be
 >    Bill> member functions.  To call a member function, you have to
 >    Bill> create a "C" function that calls the member funciton:
 >
 >    Bill> Something like this:
 >
 >    Bill> void newExtiMethod(void* arg) {
 >    Bill> static_cast<classname*>(arg)->newExitMethod(); }
 >
 >Are you sure?  Shouldnt the following code also work?
 >
 >class Foo{
 >
 >      // ...
 >      static void ExitMethod (void *arg);
 >}
 >
 >iren->SetExitMethod(&Foo::ExitMethod, NULL);
 >
 >prabhu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20011119/54e5c86d/attachment.htm>


More information about the vtkusers mailing list