Commit 452a70cd authored by David Cole's avatar David Cole
Browse files

ENH: Merge changes from main tree into VTK-5-0 branch. (cvs -q up -j1.115...

ENH: Merge changes from main tree into VTK-5-0 branch. (cvs -q up -j1.115 -j1.117 Rendering/vtkTkRenderWidget.cxx)
parent a066d255
......@@ -629,66 +629,8 @@ extern "C"
}
self->RenderWindow->UnRegister(NULL);
self->RenderWindow = NULL;
#ifdef _WIN32
/*
vtkTkRenderWidget crashes on exit when used with ActiveState Tcl, which
is thread enabled:
vtkTkRenderWidget .t
pack .t
destroy .t ;# crash in ckfree
The problem seems related to the way the vtkTkRenderWidget is
destroyed and whether or not Tcl/Tk is built with thread enabled.
A data structure (self->RW) was freed with 'ckfree' in
vtkTkRenderWidget_Destroy and we noticed that:
- ckfree() works with all our Tcl/Tk non thread-enabled, but crashes
with ActiveState thread-enabled,
- an attempt with free() works with ActiveState thread-enabled, but
crashes ParaView, VolView or KWWidgets with all our Tcl/Tk non
thread-enabled (but seems to work with VTK, beats me).
As a workaround, the code below checks if Tcl/Tk is thread-enabled,
and call one or the other. Now I'm obviously still fuzzy on this one,
because it does not really explain what's going on. My suspicion is
this one: when you build Tcl/Tk with --enable-thread, the TCL_THREAD
definition flag is defined, and this actually triggers a lot of stuff
in Tcl.h to make use of thread-safe functions. However, it does *NOT*
leave anything inside Tcl.h that says "I was compiled thread-safe".
Now I think that maybe a project like VTK that uses Tcl/Tk C API
should detect if it is about to be compiled against a thread-enabled
Tcl/Tk, and define the TCL_THREAD flag accordingly, so that when it
includes Tcl.h it uses the thread-safe API (this can be done from
CMake at configuration time). I tried it by actually defining
TCL_THREADS in VTK's vtkTcl.h, without success though. On the other
hand, that would also contradicts the fact that you should be able to
use any 8.x Tcl/Tk DLL anyway at run-time (which is further confirmed
by the fact that nothing in Tcl.h says "I was compiled thread-safe").
*/
if (Tcl_GetVar2(
self->Interp, "tcl_platform", "threaded", TCL_GLOBAL_ONLY) == NULL)
{
ckfree (self->RW);
}
else
{
free (self->RW);
}
#else
/*
It would make sense to test for Tcl/Tk threaded too on Unix platform,
but we haven't heard of any crash so far. On the other hand, the Mac
does complain if the above trick is used:
vtk(14269,0xa000ef98) malloc: *** Deallocation of a pointer not
malloced: 0x14f398d8; This could be a double free(), or free()
called with the middle of an allocated block; Try setting
environment variable MallocHelp to see tools to help debug
So let's stick to ckfree() for now.
*/
ckfree (self->RW);
#endif
}
ckfree (self->RW);
ckfree(memPtr);
}
}
......@@ -846,6 +788,11 @@ LRESULT APIENTRY vtkTkRenderWidgetProc(HWND hWnd, UINT message,
return 1;
}
if (!self->TkWin)
{
return 1;
}
// forward message to Tk handler
vtkSetWindowLong(hWnd,4,(LONG)((TkWindow *)self->TkWin)->window);
if (((TkWindow *)self->TkWin)->parentPtr)
......@@ -959,7 +906,8 @@ static int vtkTkRenderWidget_MakeRenderWindow(struct vtkTkRenderWidget *self)
vtkTclGetObjectFromPointer(self->Interp, self->RenderWindow,
"vtkRenderWindow");
#endif
self->RW = strdup(self->Interp->result);
self->RW = ckalloc(strlen(self->Interp->result) + 1);
strcpy(self->RW, self->Interp->result);
self->Interp->result[0] = '\0';
}
else
......@@ -1113,7 +1061,7 @@ vtkTkRenderWidget_MakeRenderWindow(struct vtkTkRenderWidget *self)
{
Display *dpy;
TkWindow *winPtr = (TkWindow *)self->TkWin;
vtkCarbonRenderWindow *renderWindow;
vtkCarbonRenderWindow *renderWindow = NULL;
WindowPtr parentWin;
if (self->RenderWindow)
......@@ -1134,7 +1082,8 @@ vtkTkRenderWidget_MakeRenderWindow(struct vtkTkRenderWidget *self)
vtkTclGetObjectFromPointer(self->Interp, self->RenderWindow,
"vtkRenderWindow");
#endif
self->RW = strdup(self->Interp->result);
self->RW = ckalloc(strlen(self->Interp->result) + 1);
strcpy(self->RW, self->Interp->result);
self->Interp->result[0] = '\0';
}
else
......@@ -1305,7 +1254,8 @@ vtkTkRenderWidget_MakeRenderWindow(struct vtkTkRenderWidget *self)
vtkTclGetObjectFromPointer(self->Interp, self->RenderWindow,
"vtkRenderWindow");
#endif
self->RW = strdup(self->Interp->result);
self->RW = ckalloc(strlen(self->Interp->result) + 1);
strcpy(self->RW, self->Interp->result);
self->Interp->result[0] = '\0';
}
else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment