<html>
Dear Mr Prabhu Ramachandran & Other Users:<br><br>
If I use a static member function instead of a static_cast, gdb gives the
following error when compiling:<br>
<x-tab> </x-tab>carpus.cpp:798:
cannot declare member function `carpus::MemberExitMethod(void *)' to have
static linkage<br>
<x-tab> </x-tab>carpus.cpp:
In function `static void carpus::MemberExitMethod(void *)':<br>
<x-tab> </x-tab>carpus.cpp:800:
invalid use of member `carpus::iren' in static member function<br>
<x-tab> </x-tab>carpus.cpp:801:
invalid use of member `carpus::renWindow' in static member
function<br><br>
where the line numbers are shown below:<br>
<x-tab> </x-tab>798:
static void carpus::MemberExitMethod(void *arg)<br>
<x-tab> </x-tab>799:
{<br>
<x-tab> </x-tab>800:
iren->Delete();<br>
<x-tab> </x-tab>801:
renWindow->Delete();<br>
<x-tab> </x-tab>802:
}<br><br>
If I use a static_cast, then the program compiles successfully. And
the gdb debugger gives the following error at runtime when I press
"q" to close the render window:<br>
<x-tab> </x-tab>
Program received signal SIGSEGV, Segmentation fault.<br>
<x-tab> </x-tab>
carpus::MemberExitMethod (this=0x0, arg=0x0) at carpus.cpp:800<br><br>
where line 800 is as follows:<br>
<x-tab> </x-tab>798:
void carpus::MemberExitMethod(void *arg)<br>
<x-tab> </x-tab>799:
{<br>
<x-tab> </x-tab>800:
iren->Delete(); //*******************THIS IS LINE
800*******************//<br>
<x-tab> </x-tab>801:
renWindow->Delete();<br>
<x-tab> </x-tab>802:
}<br><br>
The associated code is listed in the previous message attached
below. Please let me know if there is anything else I can provide
which may be helpful.<br><br>
Thanks,<br>
Anwar<br><br>
<br>
PR>Its hard for people to figure out the problem with pure code. A
trace from a debugger is usually <br>
PR>more helpful. Try running your code with a debugger and see where
it segfaults. <br>
PR>Also try using a static member function instead of a static_cast
etc. prabhu <br><br>
<blockquote type=cite class=cite cite>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...?<br><br>
I will show the relevant code below. My program has a <b>carpus</b>
class. This class has a method called <b>carpalRender</b> for
rendering the carpus. And a new user-defined <b>exitMethod</b> to
exit the vtk window opened by carpalRender.<br><br>
class <b>carpus<br>
</b>{<br>
private:<br><br>
//I define these as members of carpus so that I can terminate the
threads from my exit method<br><br>
vtkRenderWindowInteractor *iren;<br>
vtkRenderWindow* renWindow;<br>
vtkRenderer* scene_render;<br>
...<br><br>
public:<br>
//render to show itself<br>
void <b>carpalRender</b>(...);<br><br>
//new exit method for vtkWindowInteractor so it does not terminate
application<br>
void carpus::<b>MemberExitMethod</b>(void *arg);<br>
...<br>
};<br><br>
Now Here is the relevant code from the method carpus::carpalRender which
calls the ExitMethod.<br><br>
void carpus::<b>carpalRender</b>(...)<br>
{<br>
...<br>
renWindow = vtkRenderWindow::New();<br>
...<br><br>
// Create window interactor<br>
iren = vtkRenderWindowInteractor::New();<br>
...<br><br>
// set the user-defined C-style ExitMethod as the new exit
method<br>
iren->SetExitMethod (ExitMethod,NULL);<br><br>
// Draw the resulting scene<br>
renWindow->Render();<br>
<br>
// Enable mouse interaction <br>
iren->Start();<br><br>
//since vtkRenderWindowInteractor does not give control back to
carpalRender <br>
//any further code in carpalRender would not get executed <br>
};<br><br>
Now the following segment of code is the C-style exit method which then
executes another <b>MemberExitMethod</b> which is a member of the carpus
class.<br><br>
//*********************>>> ExitMethod
<<<<************************//<br>
void <b>ExitMethod</b>(void *arg)<br>
{<br>
static_cast<carpus*>(arg)->MemberExitMethod(arg);<br>
};<br><br>
//*********************>>> carpus::MemberExitMethod
<<<<************************//<br>
void carpus::<b>MemberExitMethod</b>(void *arg)<br>
{<br>
iren->Delete();<br>
renWindow->Delete();<br>
};</blockquote></html>