[vtkusers] Re: Error msg when destroying a vtkTkRenderWidget

Goodwin Lawlor goodwin.lawlor at ucd.ie
Tue Jun 13 11:53:37 EDT 2006

Roger Blum wrote:
> Hi vtk users,
> I have an application written in Tcl which displays a scene of different 
> actors. The user can select one actor to display in a separate window.
> To acheive this I create a new toplevel widget with an embedded 
> vtkTkRenderWidget. I create a new mapper (as a shallow copy of the original 
> mapper) and a new actor, which I add to the new renderer.
> When I close this separate window the following warning is displayed:
> Generic Warning: In 
> C:\Dashboards\Releases\rc-VTK-5-0-0-rc1\VTK\Rendering\vtkTkRenderWidget.cxx, 
> line 622
> A TkRenderWidget is being destroyed before it associated vtkRenderWindow is 
> destroyed. This is very bad and usually due to the order in which objects 
> are being destroyed. Always destroy the vtkRenderWindow before destroying 
> the user interface components.
> How do I have to destroy/delete the vtk objects created for this separate 
> window? I do not create a vtkRenderWindow explicitly. It is created by the 
> vtkTkRenderWidget. I have tried to delete/destroy the objects in various 
> sequences, nothing helped. A call to
> [tkRenderWidget GetRenderWindow] Delete
> caused error messages complaining about a non existing TempXYZ object.

In short, you have to delete the interactor too (which is created for 
you, if needed). Here's some code to destroy the window, either by 
clicking the destroy button in the title bar or pressing "e".

package require vtk
package require vtkinteraction

#console show
wm withdraw .

toplevel .w

vtkTkRenderWidget .w.renWidget

::vtk::bind_tk_render_widget .w.renWidget

pack .w.renWidget -expand 1 -fill both

set renWin [.w.renWidget GetRenderWindow]

vtkRenderer ren
   $renWin AddRenderer ren

wm protocol .w WM_DELETE_WINDOW cbCloseWindow

set iren [$renWin GetInteractor]
# remove the default callback to exit the app
$iren RemoveObserver [::vtk::get_widget_variable_value $iren ExitEventTag]
$iren AddObserver ExitEvent cbCloseWindow

proc cbCloseWindow {} {
   set renWin [.w.renWidget GetRenderWindow]

   set renCol [$renWin GetRenderers]
   for {$renCol InitTraversal} {[set ren [$renCol GetNextItem]] ne ""} 
{}      {
     $renWin RemoveRenderer $ren
     $ren Delete

   set iren [$renWin GetInteractor]
   $renWin Delete
   $iren Delete
   destroy .w

> As a quick and dirty solution: Can I prevent vtk from showing the 
> vtkOutputWindow?

You can direct the error messages to a file using vtkFileOutputWindow

vtkFileOutputWindow outputFile
   outputFile SetFileName errors.log
   outputFile SetInstance outputFile

or just switch them off:

     vtkObject obj
     obj GlobalWarningDisplayOff
     obj Delete



More information about the vtkusers mailing list