| 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.
|