Menu

#2722 Entering circumflex '^' into entry crashes TkAqua 8.6b1.1

obsolete: 8.6b1.1
closed-accepted
9
2011-01-24
2009-12-02
No

The following script:

% entry .e
% pack .e

will crash TkAqua8.6b1.1 when entering a circumflex (the ^ character) into the entry. This is true for both the i386 and the x86_64 builds. The error message is:

2009-12-02 11:17:30.936 wish-aqua8.6[6459:903] An uncaught exception was raised
2009-12-02 11:17:30.939 wish-aqua8.6[6459:903] *** -[NSCFString characterAtIndex:]: Range or index out of bounds
2009-12-02 11:17:31.023 wish-aqua8.6[6459:903] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString characterAtIndex:]: Range or index out of bounds'
*** Call stack at first throw:
(
0 CoreFoundation 0x00007fff85879444 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x00007fff8496d0f3 objc_exception_throw + 45
2 CoreFoundation 0x00007fff85879267 +[NSException raise:format:arguments:] + 103
3 CoreFoundation 0x00007fff858791f4 +[NSException raise:format:] + 148
4 Foundation 0x00007fff801803d5 -[NSCFString characterAtIndex:] + 97
5 Tk 0x00000001000c52e0 Tk_SetCaretPos + 674
6 Tk 0x00000001000cb9db Tk_MacOSXSetupTkNotifier + 701
7 Tcl 0x00000001001f4486 Tcl_DoOneEvent + 297
8 Tk 0x000000010001d8e0 Tk_MainLoop + 24
9 Tk 0x000000010002b36a Tk_MainEx + 1491
10 wish-aqua8.6 0x000000010000548b 0x0 + 4294988939
11 wish-aqua8.6 0x00000001000053d0 0x0 + 4294988752
12 ??? 0x0000000000000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Abort trap

Discussion

  • Torsten Berg

    Torsten Berg - 2009-12-02
    • assigned_to: hobbs --> das
     
  • Daniel A. Steffen

    also see 2948152

     
  • Daniel A. Steffen

    • priority: 5 --> 8
     
  • Torsten Berg

    Torsten Berg - 2010-06-25

    I tracked this down to be more general. This error occurs everytime you try to insert an accented character into an entry or text widget (or editable combobox or whatever text input widget), i.e. everywhere a key event is triggered. If you enter one of the following keys used for composed characters ´`^~¨ (keycodes 24, 24+Shift, 10, 45+alt, 32+alt), Tk crashes.

    The problem is in tkProcessKeyEvent (file tkMacOSXKeyEvent.c, line 151). The method

    [characters characterAtIndex:0] fails, because there are no characters in this event, only the keycode. There are also no modifiers at this moment ([theEvent modifierFlags] in line 54).

    The problem seems to be that this special case is just not handled/implemented. Unfortunately, my knowledge of events and all the functions in the Tk core involved here, is limited, so I can not really fix it. I tried several things but the only success was to avoid the crash without anything being inserted into the entry.

    So, what is missing here, seems to me:

    1. Enter one of the above keys (there may be some others) -> insert the corresponding character into the entry/text/whatever and select it with yellow color to mark it as special (see also section 'Setting Focus and Selection Programmatically' on http://developer.apple.com/mac/library/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html\)

    2. Enter a character that can be composed of the first one and the current one -> delete the selection and insert the composed character instead. If no such composed character exists just leave the first character alone and add the current one (maybe some special treatment for 'space').

     
  • Donal K. Fellows

    It's the composing circumflex (Option-i) that causes trouble.

     
  • Donal K. Fellows

    • priority: 8 --> 9
     
  • Uldis

    Uldis - 2010-11-15

    As pointed out in comment from 2010-06-25, this crash happens for [all] composite characters.

    In my case, a Tkinter app crashed when entering accented Latvian character using the ' (single quote) modifier key. Input locale on Mac OS X 10.6 was set to Latvian.

    Out of the two ways for entering the same accented character - using a "sticky" single quote key followed by the letter char or pressing Opt- together with the letter char - the former causes the crash while the latter shows the correct character. This confirms that the crash is caused by the "sticky" modifier key and not by the accented character itself.

     
  • Ned Deily

    Ned Deily - 2011-01-22

    This is a really nasty bug and, with the release of Cocoa Tk backports to Tk 8.5, as in the Tcl/Tk 8.5.7 shipped by Apple in Mac OS X 10.6 and the recent ActiveState Tcl/Tk 8.5.9, it is impacting more applications and users. In OS X 10.6, the Apple-supplied Python Tkinter modules and, thus, IDLE are susceptible to this crash: /usr/bin/idle2.6 and, with the US Extended input method, type Option-u (umlaut combiner) or Option-n (tilde combiner), for instance. For the Python Software Foundation (python.org) Python installers for OS X, we were intending to support 64-bit Python with a recommendation to use the ActiveState 8.5.9 Tcl/Tk (since the Apple-supplied one has so many other problems with Tkinter and IDLE) but this easy crasher seems to be a show stopper for that (http://bugs.python.org/issue10973). I see that postfix combining characters (like Shift-Option-u) work without crashing. It also appears that the system Character Viewer input does not work at all.

    Any prognosis on a fix for this problem?

     
  • Torsten Berg

    Torsten Berg - 2011-01-23

    patched version of tkMacOSXKeyEvent.c as temporary workaround for the bug

     
  • Torsten Berg

    Torsten Berg - 2011-01-23

    I uploaded a patched version of the file tkMacOSXKeyEvent.c (patched from cvs revision 1.30) that circumvents the bug by catching the condition that causes the crash in [characterAtIndex].

    This will let the character through, but not the accent used to make the composed character.

     
  • Kevin Walzer

    Kevin Walzer - 2011-01-24

    I've committed Torsten's patch--thanks, Torsten. This works around the issue by avoiding the crash, but I'm still not able to input some composite characters (option-u, for instance): the keyboard input is ignored. (Shift-option-u does work.)

    Composite characters and Unicode are surprisingly difficult to manage in Cocoa; I've spent a number of hours investigating this and was not able to find any solution to the question. Torsten's patch is the only workable solution for the moment.

     
  • Kevin Walzer

    Kevin Walzer - 2011-01-24
    • status: open --> closed-accepted