[vtkusers] RE: 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
Wed Nov 21 10:57:09 EST 2001
Dear Mr Prabhu Ramachandran & Other Users:
If I use a static member function instead of a static_cast, gdb gives the
following error when compiling:
carpus.cpp:798: cannot declare member function
`carpus::MemberExitMethod(void *)' to have static linkage
carpus.cpp: In function `static void carpus::MemberExitMethod(void
*)':
carpus.cpp:800: invalid use of member `carpus::iren' in static
member function
carpus.cpp:801: invalid use of member `carpus::renWindow' in
static member function
where the line numbers are shown below:
798: static void carpus::MemberExitMethod(void *arg)
799: {
800: iren->Delete();
801: renWindow->Delete();
802: }
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:
Program received signal SIGSEGV, Segmentation fault.
carpus::MemberExitMethod (this=0x0, arg=0x0) at carpus.cpp:800
where line 800 is as follows:
798: void carpus::MemberExitMethod(void *arg)
799: {
800: iren->Delete(); //*******************THIS IS LINE
800*******************//
801: renWindow->Delete();
802: }
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.
Thanks,
Anwar
PR>Its hard for people to figure out the problem with pure code. A trace
from a debugger is usually
PR>more helpful. Try running your code with a debugger and see where it
segfaults.
PR>Also try using a static member function instead of a static_cast etc.
prabhu
>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();
> };
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20011121/7bd8454a/attachment.htm>
More information about the vtkusers
mailing list