Tk Source Code

View Ticket
Login
2026-10-14
12:15 • Closed ticket [4a25f316]: Embedded application exits with BadDrawable when its container is destroyed plus 6 other changes artifact: 37284326 user: nemethi
11:58
Fix [5f7ba8c5a3]: Restore the fix for [4a25f316f7] check-in: 474ec9d0 user: csaba tags: core-8-6-branch
09:22
Fix [5f7ba8c5a3]: Restore the fix for [4a25f316f7] check-in: d5effc94 user: csaba tags: core-9-0-branch
2026-10-09
17:14
Fix [5f7ba8c5a3]: Restore the fix for [4a25f316f7] check-in: 54ffe89f user: jan.nijtmans tags: trunk, main
15:56 • Ticket [4a25f316] Embedded application exits with BadDrawable when its container is destroyed status still Pending with 3 other changes artifact: 052730a4 user: serhiy.storchaka
15:55 • Ticket [5f7ba8c5] Leakage in trunk, with --disable-xft build status still Open with 3 other changes artifact: e3e48435 user: serhiy.storchaka
15:17
Fix [5f7ba8c5a3]: Restore the fix for [4a25f316f7], which was backed out because the table of deleted windows grew in loops which created and destroyed windows without a round trip to the server (entry-5.20 and place-14.1 failed with --enable-symbols=all). Only an embedded application can have its windows destroyed by someone else, so record deleted windows only if a toplevel of the application has been embedded on that display. closed check-in: 8bb13f5c user: serhiy.storchaka tags: embed-container-destroyed
13:58 • Pending ticket [4a25f316]: Embedded application exits with BadDrawable when its container is destroyed plus 4 other changes artifact: bb949463 user: jan.nijtmans
2026-10-08
17:51 • Closed ticket [3610628f]: Notebook in Paned Window crashes app when closed plus 5 other changes artifact: 838394b6 user: serhiy.storchaka
2026-10-07
16:33 • Closed ticket [4a25f316]: Embedded application exits with BadDrawable when its container is destroyed plus 8 other changes artifact: 289f3411 user: jan.nijtmans
16:31
Fix [4a25f3]: Embedded application exits with BadDrawable when its container is destroyed check-in: 79f2efbc user: jan.nijtmans tags: core-8-6-branch
14:36
Fix [4a25f3]: Embedded application exits with BadDrawable when its container is destroyed check-in: be8493a6 user: jan.nijtmans tags: core-9-0-branch
13:50 • Closed ticket [ff0311b7]: unixEmbed-9.2 EmbedWindowDeleted procedure failing on Ubuntu plus 7 other changes artifact: eae7350a user: jan.nijtmans
13:48
Fix [4a25f3]: Embedded application exits with BadDrawable when its container is destroyed check-in: dd18288b user: jan.nijtmans tags: trunk, main
13:15 • Ticket [ff0311b7] unixEmbed-9.2 EmbedWindowDeleted procedure failing on Ubuntu status still Open with 3 other changes artifact: 6840737e user: serhiy.storchaka
08:25 • Ticket [2128087f] menubutton menu-traversal shortkeys doesn't work status still Closed with 3 other changes artifact: 8627b215 user: serhiy.storchaka
2026-09-26
20:15 • Ticket [4a25f316] Embedded application exits with BadDrawable when its container is destroyed status still Open with 3 other changes artifact: b8115ef1 user: serhiy.storchaka
20:12
Fix [4a25f316f7]: an embedded application exited with BadDrawable when its container was destroyed while it had pending drawing. ErrorProc() now ignores BadDrawable errors like BadWindow errors, also for windows deleted after the failed request (this check was lost in 8.6 together with the XID management). Recently deleted windows are recorded in the new field deletedWinTable at the end of TkDisplay. New test unixEmbed-9.3. closed check-in: d6f016b5 user: serhiy.storchaka tags: embed-container-destroyed
20:12 • New ticket [4a25f316] Embedded application exits with BadDrawable when its container is destroyed. artifact: b719039f user: serhiy.storchaka

Ticket UUID: 4a25f316f7bb5d3bd50d1608b66f6acb5ca445fd
Title: Embedded application exits with BadDrawable when its container is destroyed
Type: Bug Version: 8.6.18, 9.0.5, 9.1b1
Submitter: serhiy.storchaka Created on: 2026-09-26 20:12:03
Subsystem: 74. Application Embedding Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-14 12:15:34
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-14 12:15:34
Description:

An embedded Tk application can exit when its container is destroyed while it still has pending drawing:

X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  55 (X_CreateGC)

Destroying the container window also destroys the embedded window in the X server. If the embedded application redraws its toplevel before it has processed that, the drawing request fails with BadDrawable. ErrorProc() in tkError.c ignores such errors for windows deleted externally, but only BadWindow errors, so this one goes to the default Xlib handler, which exits the process.

The error can also arrive after Tk has already deleted the window. Tk 8.4 and 8.5 ignored errors for recently deleted windows (TkpWindowWasRecentlyDeleted()), but this was removed together with the XID management in [8356aa0eec], so this case is not handled since 8.6.0 either.

Reproducer (parent.tcl runs child.tcl embedded in a container frame):

# child.tcl
. configure -bg green -highlightthickness 2 -bd 2 -relief sunken
update
puts ready; flush stdout
gets stdin            ;# no X events are processed meanwhile
. configure -bg blue
update idletasks
winfo pointerxy .
puts alive; flush stdout

# parent.tcl
frame .f -container 1 -width 200 -height 100
pack .f; update
set fd [open "|[list [info nameofexecutable] child.tcl -use [winfo id .f]] 2>@1" r+]
fconfigure $fd -buffering line
while {[gets $fd line] >= 0 && $line ne "ready"} {}
destroy .f
update
puts $fd go
puts [read $fd]
exit

The child prints the X error and exits instead of printing "alive" (every time with core-8-6-branch, core-9-0-branch and main).

This also makes test unixEmbed-9.2 fail in about 1 of 6 runs with error flushing "file9": broken pipe: the child process used by the tests has exited after the container of its embedded toplevel was destroyed in an earlier test. The X error message is not visible, because the child's stderr is only read when its channel is closed.

[3610628fff] may be a similar issue.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-14 12:15:34:

Restored the backed out fix in main, core-9-0-branch, and core-8-6-branch by commits [54ffe89f] (Jan), [d5effc94], and [474ec9d09]. Closing the ticket.


serhiy.storchaka added on 2026-10-09 15:56:29:

The growth is fixed in branch embed-container-destroyed, see [5f7ba8c5a3]: deleted windows are now recorded only after a toplevel of the application has been embedded. The new check-in is on top of main and restores the backed out fix, so a plain merge brings it back. The fix was also backed out in core-9-0-branch and core-8-6-branch, where the backout needs to be reverted too.


jan.nijtmans added on 2026-10-09 13:58:01:

It looks like this fix is causing a memory leakage. See [this] ticket.

So, what shall we do?


jan.nijtmans added on 2026-10-07 16:33:13:

Fixed in [dd18288b38855f19|trunk]. Backported to core-9-0-branch and core-8-6-branch.

Many thanks!

Closing


serhiy.storchaka added on 2026-09-26 20:15:26:

Proposed fix in branch embed-container-destroyed: ErrorProc() ignores BadDrawable errors like BadWindow errors, also for windows deleted after the failed request. Recently deleted windows are recorded in a new field at the end of TkDisplay.

unixEmbed-9.2 no longer sporadically fails. The new test unixEmbed-9.3 adds a more reliable reproducer.