Tk Source Code

View Ticket
Login
Ticket UUID: bd352828bbea701a34e99e113de2998272c849fa
Title: Windows: clipboard clear crashes before the main window exists
Type: Bug Version: 8.6.18, 9.0.5, 9.1.0
Submitter: serhiy.storchaka Created on: 2026-10-09 15:05:12
Subsystem: 52. [clipboard] Assigned To:
Priority: 5 Medium Severity: Important
Status: Open Last Modified: 2026-10-09 16:21:40
Resolution: None Closed By:
    Closed on:
Description:

On Windows, clipboard clear crashes wish (access violation) when its window (the -displayof one, or ".") has not been made yet: as the first command of a script, after wm withdraw ., or for a widget not yet packed or a new toplevel before update:

clipboard clear
puts ok
update
button .b
clipboard clear -displayof .b

Other clipboard and selection commands (clipboard append, also with such a -displayof window, clipboard get, selection own) do not crash.

The clear subcommand calls TkSelUpdateClipboard() with the -displayof window ("." by default), and on Windows that takes TkWinGetHWND(winPtr->window) of it: a NULL Window while the window has not been made yet. Tk_ClipboardAppend() passes dispPtr->clipWindow instead, which TkClipInit() has made exist.

Found while running Tktaalik tests on Windows.

User Comments: serhiy.storchaka added on 2026-10-09 16:21:40:

Proposed fix in branch win-clipboard-clear-unmade: clipboard clear updates the Windows clipboard with the clipboard window, as clipboard append does, instead of the -displayof window. Test clipboard-7.21 crashes without the fix and passes with it on Windows 11.