<html>
Dear Mr Prabhu Ramachandran &amp; 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>carpus.cpp:798:
cannot declare member function `carpus::MemberExitMethod(void *)' to have
static linkage<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>carpus.cpp:
In function `static void carpus::MemberExitMethod(void *)':<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>carpus.cpp:800:
invalid use of member `carpus::iren' in static member function<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>798:&nbsp;
static void carpus::MemberExitMethod(void *arg)<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>799:&nbsp;
{<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>800:&nbsp;&nbsp;&nbsp;
iren-&gt;Delete();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>801:&nbsp;&nbsp;&nbsp;
renWindow-&gt;Delete();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>802:&nbsp;
}<br><br>
If I use a static_cast, then the program compiles successfully.&nbsp; And
the gdb debugger gives the following error at runtime when I press
&quot;q&quot; to close the render window:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;
Program received signal SIGSEGV, Segmentation fault.<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>&nbsp;&nbsp;
carpus::MemberExitMethod (this=0x0, arg=0x0) at carpus.cpp:800<br><br>
where line 800 is as follows:<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>798:&nbsp;
void carpus::MemberExitMethod(void *arg)<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>799:&nbsp;
{<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>800:&nbsp;&nbsp;&nbsp;
iren-&gt;Delete();&nbsp; //*******************THIS IS LINE
800*******************//<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>801:&nbsp;&nbsp;&nbsp;
renWindow-&gt;Delete();<br>
<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab>802:&nbsp;
}<br><br>
The associated code is listed in the previous message attached
below.&nbsp; 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&gt;Its hard for people to figure out the problem with pure code. A
trace from a debugger is usually <br>
PR&gt;more helpful. Try running your code with a debugger and see where
it segfaults. <br>
PR&gt;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.&nbsp; We defined a user-defined exitMethod to give
control back to program by terminating the threads to
vtkRenderWindowInteractor and vtkRenderWindow.&nbsp; This gives me a
segmentation fault when my exitMethod tries to break the threads.&nbsp;
Is there another way...?<br><br>
I will show the relevant code below.&nbsp; My program has a <b>carpus</b>
class.&nbsp; This class has a method called <b>carpalRender</b> for
rendering the carpus.&nbsp; 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>
&nbsp; //I define these as members of carpus so that I can terminate the
threads from my exit method<br><br>
&nbsp; vtkRenderWindowInteractor *iren;<br>
&nbsp; vtkRenderWindow* renWindow;<br>
&nbsp; vtkRenderer* scene_render;<br>
&nbsp; ...<br><br>
public:<br>
&nbsp; //render to show itself<br>
&nbsp; void <b>carpalRender</b>(...);<br><br>
&nbsp; //new exit method for vtkWindowInteractor so it does not terminate
application<br>
&nbsp; void carpus::<b>MemberExitMethod</b>(void *arg);<br>
&nbsp; ...<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>
&nbsp; ...<br>
&nbsp; renWindow = vtkRenderWindow::New();<br>
&nbsp; ...<br><br>
&nbsp; // Create window interactor<br>
&nbsp; iren = vtkRenderWindowInteractor::New();<br>
&nbsp; ...<br><br>
&nbsp; // set the user-defined C-style ExitMethod as the new exit
method<br>
&nbsp; iren-&gt;SetExitMethod (ExitMethod,NULL);<br><br>
&nbsp; // Draw the resulting scene<br>
&nbsp; renWindow-&gt;Render();<br>
&nbsp;<br>
&nbsp; // Enable mouse interaction <br>
&nbsp; iren-&gt;Start();<br><br>
&nbsp; //since vtkRenderWindowInteractor does not give control back to
carpalRender <br>
&nbsp; //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>
//*********************&gt;&gt;&gt; ExitMethod
&lt;&lt;&lt;&lt;************************//<br>
&nbsp; void <b>ExitMethod</b>(void *arg)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp;
static_cast&lt;carpus*&gt;(arg)-&gt;MemberExitMethod(arg);<br>
&nbsp; };<br><br>
//*********************&gt;&gt;&gt; carpus::MemberExitMethod
&lt;&lt;&lt;&lt;************************//<br>
&nbsp; void carpus::<b>MemberExitMethod</b>(void *arg)<br>
&nbsp; {<br>
&nbsp;&nbsp;&nbsp; iren-&gt;Delete();<br>
&nbsp;&nbsp;&nbsp; renWindow-&gt;Delete();<br>
&nbsp;};</blockquote></html>