[vtkusers] tcl and segmentation fault

hhiraki at lab.nig.ac.jp hhiraki at lab.nig.ac.jp
Thu Jul 25 22:58:53 EDT 2002


On Thu, 25 Jul 2002 16:06:24 -0500, Dave Semeraro wrote:
> 
> In running the vtk examples ( VTK/Examples/Rendering/Tcl/cylinder.tcl in 
> particular) my tcl interpreter
> gives a segmentation fault when I exit the program via the "q" or "e" 
> keyboard commands in the
> vtkRenderWindowInteractor. I am running VTK4.0 with RedHat Linux 7.2. Has 
> anyone else seen
> this sort of behavior? The examples work just fine except I get a 
> segmentation violation when I
> quit. It just happens with tcl. The Cxx cylinder example does not seg fault 
> when I quit. I am
> seeing version 8.2 of tcl in the /usr/libs directory. Perhaps a tcl version 
> problem?
> 

I suffered the problem and found that "vtkTclInterpStruct" is freed before 
objects (vtkTkImageViewerWidget in my case) are freed. The attached patch 
is a halfway hack. (Digression: Tcl_StaticPackage is required to fit the 
package mechanism of Tcl. Please see tkAppInit.c of recent Tcl/Tk.)
A right solution may be to execute "vtkCommand DeleteAllObjects" when the 
system free vtkTclInterpStruct. But I couldn't go this way because 
Wrapping/vtkWrapTclInit.c seems not to be used now.
Regards,

Hideaki Hiraki
-------------- next part --------------
--- Wrapping/Tcl/tkAppInit.cxx.in.orig	Mon Jun  3 18:11:11 2002
+++ Wrapping/Tcl/tkAppInit.cxx.in	Fri Jul 26 10:46:16 2002
@@ -100,16 +100,19 @@
   if (Tcl_Init(interp) == TCL_ERROR) {
   return TCL_ERROR;
   }
-#ifdef VTK_USE_RENDERING
-  if (Tk_Init(interp) == TCL_ERROR) {
-  return TCL_ERROR;
-  }
-#endif
   /* init the core vtk stuff */
   if (Vtkcommontcl_Init(interp) == TCL_ERROR) 
     {
     return TCL_ERROR;
     }
+#ifdef VTK_USE_RENDERING
+  if (Tk_Init(interp) == TCL_ERROR) {
+  return TCL_ERROR;
+  }
+#if (((TK_MAJOR_VERSION == 4)&&(TK_MINOR_VERSION >= 1))||((TK_MAJOR_VERSION == 8)&&(TK_MINOR_VERSION >= 0)))
+  Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
+#endif
+#endif
   if (Vtkfilteringtcl_Init(interp) == TCL_ERROR) 
     {
     return TCL_ERROR;


More information about the vtkusers mailing list