Tk Source Code

View Ticket
Login
2026-10-08
15:39 • Ticket [fb13231f] Messagebox can crash app on mac status still Open with 3 other changes artifact: f04fe5ab user: chrstphrchvz
13:02 • Ticket [c03b8eb7] Document the requirement not to call tk_messageBox from idle events under aqua status still Open with 3 other changes artifact: bd31609b user: serhiy.storchaka
2022-05-01
11:54 • Ticket [c03b8eb7]: 3 changes artifact: 61fc8eb4 user: chrstphrchvz
2021-03-23
19:31 • Ticket [815f779d] macOS crashes status still Open with 3 other changes artifact: efd5b536 user: chrstphrchvz
2020-09-03
13:47 • New ticket [c03b8eb7] Document the requirement not to call tk_messageBox from idle events under aqua. artifact: 856a3a68 user: anonymous

Ticket UUID: c03b8eb71f2fa05c73eb9a92625e353a084895a6
Title: Document the requirement not to call tk_messageBox from idle events under aqua
Type: Patch Version: 8.6.10
Submitter: anonymous Created on: 2020-09-03 13:47:59
Subsystem: 99. Other Assigned To: nobody
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2026-10-08 13:02:41
Resolution: None Closed By: nobody
    Closed on:
Description:

I've been puzzling for some time over an application that crashes under some circumstances when macOS starts it when the user double-clicks on a file associated with it; the problem turned out to be that the file had a formatting error, causing a tk_messageBox call (from, ultimately, a callee of ::tk::mac::OpenDocument) to notify the user that the file's corrupt.

According to ticket 1b286c99aef5183365641ba2de55446e57deac94 this is because it's not correct to call tk_messageBox from within an idle callback, and I can see after some source-diving that the ::tk::mac::* AppleEvent handler procs are called from idle callbacks. I can't find either of these facts documented in the manual pages; short of fixing the surprising behavior somehow, I suggest a diff vaguely like the following:


Index: doc/chooseColor.n
==================================================================
--- doc/chooseColor.n
+++ doc/chooseColor.n
@@ -39,10 +39,15 @@
 .SH EXAMPLE
 .PP
 .CS
 button .b \-bg [tk_chooseColor \-initialcolor gray \-title "Choose color"]
 .CE
+.SH BUGS
+.PP
+Under the aqua windowing system, modal dialogs should not be called from idle
+events, because these may internally be executed within contexts where an aqua
+native modal dialog is not permitted, resulting in a C-level exception.
 .SH KEYWORDS
 color, color selection, dialog
 '\" Local Variables:
 '\" mode: nroff
 '\" End:

Index: doc/chooseDirectory.n
==================================================================
--- doc/chooseDirectory.n
+++ doc/chooseDirectory.n
@@ -62,10 +62,15 @@
    label .l \-text "Selected $dir"
 }
 .CE
 .SH "SEE ALSO"
 tk_getOpenFile(n), tk_getSaveFile(n)
+.SH BUGS
+.PP
+Under the aqua windowing system, modal dialogs should not be called from idle
+events, because these may internally be executed within contexts where an aqua
+native modal dialog is not permitted, resulting in a C-level exception.
 .SH KEYWORDS
 directory, selection, dialog, platform-specific
 '\" Local Variables:
 '\" mode: nroff
 '\" End:

Index: doc/getOpenFile.n
==================================================================
--- doc/getOpenFile.n
+++ doc/getOpenFile.n
@@ -198,10 +198,15 @@
     # Open the file ...
 }
 .CE
 .SH "SEE ALSO"
 tk_chooseDirectory
+.SH BUGS
+.PP
+Under the aqua windowing system, modal dialogs should not be called from idle
+events, because these may internally be executed within contexts where an aqua
+native modal dialog is not permitted, resulting in a C-level exception.
 .SH KEYWORDS
 file selection dialog
 '\" Local Variables:
 '\" mode: nroff
 '\" End:

Index: doc/messageBox.n
==================================================================
--- doc/messageBox.n
+++ doc/messageBox.n
@@ -113,10 +113,15 @@
     yes exit
     no {\fBtk_messageBox\fR \-message "I know you like this application!" \e
             \-type ok}
 }
 .CE
+.SH BUGS
+.PP
+Under the aqua windowing system, modal dialogs should not be called from idle
+events, because these may internally be executed within contexts where an aqua
+native modal dialog is not permitted, resulting in a C-level exception.
 .SH KEYWORDS
 message box
 '\" Local Variables:
 '\" mode: nroff
 '\" End:

Index: doc/tk_mac.n
==================================================================
--- doc/tk_mac.n
+++ doc/tk_mac.n
@@ -295,12 +295,17 @@
 .TP
 \fB\-imageFile\fR
 .
 image at given path
 .RE
+.SH "BUGS"
+.PP
+Event handler callbacks are executed within an idle event, and should not
+call modal dialog commands such as tk_messageBox or tk_getOpenFile directly;
+if necessary it is safer to do so in a timer event.
 .SH "SEE ALSO"
 bind(n), wm(n)
 .SH KEYWORDS
 about dialog, antialiasing, Apple event, icon, NSImage
 '\" Local Variables:
 '\" mode: nroff
 '\" End:

User Comments: serhiy.storchaka added on 2026-10-08 13:02:41:

The handlers for Apple events are no longer run as idle callbacks (they are called directly or from a timer), and since [33b3af1cea] menu actions are run as idle tasks, so the proposed note would now be misleading. The actual problem was a modal dialog opened while AppKit is drawing: in 8.6 idle tasks run inside drawRect:, and in 9.0 they can still run inside updateLayer when a view is first shown or during a live resize. Marc, can a dialog opened in those cases still crash? If so, it is probably better to defer it in Tk than to document it.


chrstphrchvz added on 2022-05-01 11:54:08:

Subscribing myself in case of updates.