Tk Source Code

View Ticket
Login
Ticket UUID: cccd0b7f81eef501670052459c653ba96455c034
Title: Windows: [winfo isdark] crashes on a window which was never mapped
Type: Bug Version: 9.1.0
Submitter: serhiy.storchaka Created on: 2026-10-22 22:03:33
Subsystem: 68. Win Window Operations Assigned To: oehhar
Priority: 5 Medium Severity: Critical
Status: Closed Last Modified: 2026-10-23 08:44:22
Resolution: Fixed Closed By: oehhar
    Closed on: 2026-10-23 08:44:22
Description:

On Windows, winfo isdark crashes when the window has no HWND yet, that is, when it was never mapped:

package require Tk
wm withdraw .
puts [winfo isdark .]

tktest91 and wish91 exit with an access violation (0xC0000005) in tcl9tk91.dll. It also crashes for . before the first update, without wm withdraw. This is probably why tests wm-attributes-1.3.13 and winWm-10.4 say "Without the following update, the command fails".

TkpWindowIsDark() in win/tkWinWm.c calls Tk_GetHWND(Tk_WindowId(tkwin)), and Tk_WindowId() is None for a window which does not exist yet.

Fixed in branch win-isdark-unmapped: TkpWindowIsDark() calls Tk_MakeWindowExist() first. New tests winfo-15.1 and winfo-15.2. Tested on Windows 11: winfo.test, wm.test and winWm.test pass.

User Comments: oehhar added on 2026-10-23 08:44:22:

The following in a console crashes wish:

toplevel .t;wm withdraw .t;winfo isdark .t

The fix and test is effective.

Merged to main by [bdb7edf927982f35]. No other merges, as this a a 9.1 feature.

Thanks, Serhiy!

Harald