Tk Source Code

View Ticket
Login
Ticket UUID: 3610628
Title: Notebook in Paned Window crashes app when closed
Type: Bug Version: current: 8.6.0
Submitter: stevenaaus Created on: 2013-04-11 21:31:19
Subsystem: 88. Themed Tk Assigned To: jenglish
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-22 17:22:36
Resolution: Out of Date Closed By: serhiy.storchaka
    Closed on: 2026-10-08 17:51:20
Description:
Scid vs PC uses embeded toplevels inside notebook and panedwidnows.
All wish-8.5 series code is fine, but 8.6.0 and todays (April 6) trunk
crash when closing a panedwindow and/or notebook.Via keyboard bindings.

  svn co https://scidvspc.svn.sourceforge.net/svnroot/scidvspc
  cd scidvspc
./configure TCL_VERSION=8.6
 make install
 /usr/local/bin/scid
 press f2 twice

 X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  10 (X_UnmapWindow)
  Resource id in failed request:  0x3e00995
  Serial number of failed request:  34177
  Current serial number in output stream:  34182

Sorry for the shitty bug report. I'm trying to find a testcase , but so far am unable.
User Comments: serhiy.storchaka added on 2026-10-08 17:51:20:

I could not reproduce this with Tk 8.6.0, 8.6.10, 8.6.18 or 9.1 with a script that docks and undocks notebook tabs with wm manage and wm forget and destroys them from a <Destroy> binding inside catch. If the docked windows were embedded toplevels (-use), it may have been fixed by [4a25f316f7] (X errors when the container of an embedded window is destroyed). Since the application code was rewritten and there is no test case, I close this ticket. Please reopen it with a script if it still happens with a current Tk.


fvogel added on 2020-01-04 11:07:13:

What your code seems to do is something like:

package require Tk

proc cleanup {} {
  puts DestroyingSTART
  bind .t <Destroy> {}
  foreach ta [.t.n tabs] {
    .t.n forget $ta
    destroy $ta
  }
  destroy .t
  puts DestroyingEND
}

toplevel .t
pack [::ttk::notebook .t.n] -fill both -expand true
foreach tabs {Edit Check Close} {
    ::ttk::entry .t.n.[string tolower $tabs]
    .t.n add .t.n.[string tolower $tabs] -text $tabs
}

bind .t <Destroy> {cleanup}
  foreach ta [.t.n tabs] {
    bind .ta <Destroy> {cleanup}
  }

# simulate keyboard generate of a Destroy event
after 1000 {event generate .t <Destroy>}

But I cannot make this crash. Some specific bit must be missing.


fvogel added on 2020-01-04 11:05:29:

I have tried to svn update to somewhere close to your version 4.12:

svn update -r1913

Then I have configured:

./configure TCL_VERSION=8.6 TCL_INCLUDE=/home/francois/Documents/tcltk/fossil/tcltk/include/ TCL_LIBRARY=/home/francois/Documents/tcltk/fossil/tcltk/lib/tcl8.6/ TK_LIBRARY=/home/francois/Documents/tcltk/fossil/tcltk/lib/tk8.6/

and make install. After quite a lot of warnings, the build fails with:

src/stored.o: dans la fonction « StoredLine::Init() »:
stored.cpp:(.text+0x174): référence indéfinie vers « PgnParser::~PgnParser() »
collect2: error: ld returned 1 exit status
Makefile:365: recipe for target 'pgnscid' failed
make: *** [pgnscid] Error 1

I don't know how to reproduce this and cannot go further on this I think.


stevenaaus added on 2019-12-31 08:28:51:
We have removed this code. But installing 4.12 and disabling the safegurad we have, this still crashes in 8.6.10. 
Sorry , but am reticent to debug this, as we have rewritten the code, and have several other active regressions to fix. If you wwant to debug it, install scidvspc 4.12 and make this change. You may have to remove any current $HOME/.scidvspc too

--- tcl/utils/win.tcl   2019-12-31 18:27:28.226639925 +1000
+++ win.tcl.test        2019-12-31 18:27:24.822641042 +1000
@@ -217,9 +217,7 @@
     if { [lsearch  [$nb tabs] $dockw ] != -1 } {
       $nb forget $dockw
       # Wish 8.6 "catch destroy" dumps core - S.A.
-      if {!$::docking::buggywish} {
        catch {destroy $dockw}
-      }
       ::docking::_cleanup_tabs $nb
       return
     }

fvogel added on 2019-12-30 16:45:52:
Steven, do you still see this in your app with 8.6.10? I have reviewed the info you provide in this ticket but I'm afraid it's inconclusive.

stevenaaus added on 2013-04-12 05:53:30:
Bug in Wish-8.6 seems to be one with "catch"

Catching this code is generating core dumps.
Without the catch, it works fine (note the extraneous destroy is commented out)

    catch {
      foreach nb [array names tbs] {
        if { [lsearch  [$nb tabs] $dockw ] != -1 } {
          $nb forget $dockw
          ### This seems wrong
          # destroy $dockw
          ::docking::_cleanup_tabs $nb
          return
        }
      }
    }

stevenaaus added on 2013-04-12 05:29:20:
Ok - this seems resolved. 
App is probably detroying a non-existing window.

Wish-8.6 should probably not crash though. Cheers.

stevenaaus added on 2013-04-12 04:58:07:
Well that is weird.
If i remove the two catches here, i can avoid a fail under some conditions.
Is bug related to "catch"  itself ?

  catch {
    bind $w <Destroy> {}
    bind $dockw <Destroy> {}
  }

  # Maybe during Scid closing, some race conditions lead to exceptions ? In case, catch this by default
  catch {
    foreach nb [array names tbs] {
      if { [lsearch  [$nb tabs] $dockw ] != -1 } {
        $nb forget $dockw
        destroy $dockw
        ::docking::_cleanup_tabs $nb
        return
      }
    }
  }

stevenaaus added on 2013-04-12 04:46:42:
To be a little more specific, i think the problem is not related to Key input,
but rather the order of widget destroy.
This code works

  set tabid [$w select]
  $w forget $tabid
  destroy $tabid
  _cleanup_tabs $w

but this code fails
  
  proc createToplevelFinalize {w} {
  if { $::docking::USE_DOCKING } {
    bind $w <Destroy> +[ namespace code "::docking::cleanup $w %W"]

Any ideas on a work around even ? But i think wish-8.6.0 code is faulty.