Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter iOS 12.0 textfield crash with CJK input method #22201

Closed
HipSze opened this issue Sep 24, 2018 · 13 comments
Closed

Flutter iOS 12.0 textfield crash with CJK input method #22201

HipSze opened this issue Sep 24, 2018 · 13 comments
Assignees
Labels
a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems c: crash Stack traces logged to the console engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically

Comments

@HipSze
Copy link

HipSze commented Sep 24, 2018

Steps to Reproduce

  1. Create two textfields

  2. Select some characters in Chinese( Chinese(Traditional) - Cangjie) keyboard in the first textfield, then select the second textfield without choosing a Chinese character from the prediction.
    Here is the example image:
    https://www.dropbox.com/s/gt540b5188egfvp/1.png?dl=0

  3. the app will crash (only in iOS 12.0, it would not crash in iOS 11.4)

Flutter console show:

*** First throw call stack:
(
0   CoreFoundation                      0x000000010b12029b __exceptionPreprocess + 331
1   libobjc.A.dylib                     0x000000010a6c4735 objc_exception_throw + 48
2   CoreFoundation                      0x000000010b1200f5 +[NSException raise:format:] + 197
3   CoreFoundation                      0x000000010b0666e3 -[__NSCFString substringWithRange:] + 163
4   UIKitCore                           0x000000011497fb5a -[UIKeyboardImpl hasMarkedText] + 143
5   UIKitCore                           0x000000011496f3a8 __43-[UIKeyboardImpl generateAutofillCandidate]_block_invoke + 51
6   UIKitCore                           0x00000001149da9bf -[UIKeyboardTaskEntry execute:] + 169
7   UIKitCore                           0x00000001149d91ae -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 374
8   UIKitCore  <…>
Lost connection to device.
Exited (sigterm)

Xcode console show:

2018-09-24 12:47:07.185255+0800 Runner[278:28523] *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range {0, 3} out of bounds; string length 0'
*** First throw call stack:
(0x1b4ccbf78 0x1b3ec4284 0x1b4bcc75c 0x1b4bba278 0x1e1e1abe0 0x1e1e09b94 0x1e1e77124 0x1e1e7574c 0x1e1e76174 0x1e1e09b44 0x1e1e1c3c8 0x105abe944 0x105abfe38 0x105ab2fa8 0x105acd628 0x105acf25c 0x105b1ee24 0x105adca88 0x105adf8c8 0x1b4c590a4 0x1b4c58dd0 0x1b4c585c4 0x1b4c53284 0x1b4c52844 0x1b6f01be8 0x1e2001428 0x104445cb4 0x1b4708020)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Logs

Analyzing ctm...

   info • Unused import: 'package:geocoder/geocoder.dart' • lib/drawerPage/location_page.dart:5:8 • unused_import
   info • The value of the local variable '_isLoggin' isn't used • lib/login.dart:67:10 • unused_local_variable

2 issues found. (ran in 1.7s)
[✓] Flutter (Channel beta, v0.8.2, on Mac OS X 10.13.6 17G2307, locale en-HK)
    • Flutter version 0.8.2 at /Users/kenwong/Development/flutter
    • Framework revision 5ab9e70727 (2 weeks ago), 2018-09-07 12:33:05 -0700
    • Engine revision 58a1894a1c
    • Dart version 2.1.0-dev.3.1.flutter-760a9690c2

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.1)
    • Android SDK at /Users/kenwong/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.0, Build version 10A255
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 27.1.1
    • Dart plugin version 173.4700
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] IntelliJ IDEA Community Edition (version 2018.2)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 26.0.3
    • Dart plugin version 182.3569.4

[✓] VS Code (version 1.27.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.18.0

[✓] Connected devices (1 available)
    • iPhone XS Max • B3E2C057-F13D-4916-A3CE-D8D0BE924DC5 • ios • iOS 12.0 (simulator)

• No issues found!
@zoechi zoechi added a: text input Entering text in a text field or keyboard related problems a: internationalization Supporting other languages or locales. (aka i18n) platform-ios iOS applications specifically engine flutter/engine repository. See also e: labels. labels Sep 24, 2018
@zoechi zoechi added this to the Goals milestone Sep 24, 2018
@HipSze HipSze changed the title Flutter iOS 12.0 textfield type Chinese crash bug Flutter iOS 12.0 textfield crash with CJK input method Sep 26, 2018
@najeira
Copy link
Contributor

najeira commented Oct 11, 2018

I got similar crashes:

Fatal Exception: NSRangeException
0  CoreFoundation                 0x189363ef8 __exceptionPreprocess
1  libobjc.A.dylib                0x188531a40 objc_exception_throw
2  CoreFoundation                 0x189268ac4 -[NSCache init]
3  CoreFoundation                 0x189256cdc -[__NSCFString substringWithRange:]
4  UIKitCore                      0x1b5a0ff8c -[UIKeyboardImpl hasMarkedText]
5  UIKitCore                      0x1b59ff5f8 __43-[UIKeyboardImpl generateAutofillCandidate]_block_invoke
6  UIKitCore                      0x1b5a69064 -[UIKeyboardTaskEntry execute:]
7  UIKitCore                      0x1b5a67774 -[UIKeyboardTaskQueue continueExecutionOnMainThread]
8  UIKitCore                      0x1b5a6814c -[UIKeyboardTaskQueue performTask:]
9  UIKitCore                      0x1b59ff5ac -[UIKeyboardImpl generateAutofillCandidate]
10 UIKitCore                      0x1b5a11670 -[UIKeyboardImpl selectionDidChange:]
11 Flutter                        0x102f6db90 (Missing)
12 Flutter                        0x102f6f084 (Missing)
13 Flutter                        0x102f61dc8 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke
14 Flutter                        0x102f7dc6c shell::HeadlessPlatformViewIOS::HandlePlatformMessage(fml::RefPtr<blink::PlatformMessage>)
15 Flutter                        0x102fba4b4 std::__1::__function::__func<shell::Shell::OnEngineHandlePlatformMessage(fml::RefPtr<blink::PlatformMessage>)::$_26, std::__1::allocator<shell::Shell::OnEngineHandlePlatformMessage(fml::RefPtr<blink::PlatformMessage>)::$_26>, void ()>::operator()()
16 Flutter                        0x102f8b01c fml::MessageLoopImpl::RunExpiredTasks()
17 Flutter                        0x102f8c328 fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*)
18 CoreFoundation                 0x1892f2bf0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
19 CoreFoundation                 0x1892f2920 __CFRunLoopDoTimer
20 CoreFoundation                 0x1892f2154 __CFRunLoopDoTimers
21 CoreFoundation                 0x1892ed030 __CFRunLoopRun
22 CoreFoundation                 0x1892ec5b8 CFRunLoopRunSpecific
23 GraphicsServices               0x18b560584 GSEventRunModal
24 UIKitCore                      0x1b5be7558 UIApplicationMain
25 Runner                         0x10230d5e4 main (AppDelegate.swift:14)
26 libdyld.dylib                  0x188dacb94 start

@buaashuai
Copy link

buaashuai commented Oct 12, 2018

I meet this similar crash too:

Trapped uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range {7, 5} out of bounds; string length 4' 
(
	0   CoreFoundation                      0x00000001d1b9ef10 <redacted> + 252
	1   libobjc.A.dylib                     0x00000001d0d6ca40 objc_exception_throw + 56
	2   CoreFoundation                      0x00000001d1aa3ac4 <redacted> + 0
	3   CoreFoundation                      0x00000001d1a91cdc <redacted> + 168
	4   UIKitCore                           0x00000001fdf8ff8c <redacted> + 144
	5   UIKitCore                           0x00000001fdf7f5f8 <redacted> + 60
	6   UIKitCore                           0x00000001fdfe9064 <redacted> + 200
	7   UIKitCore                           0x00000001fdfe7774 <redacted> + 384
	8   UIKitCore                           0x00000001fdfe814c <redacted> + 136
	9   UIKitCore                           0x00000001fdf7f5ac <redacted> + 136
	10  UIKitCore                           0x00000001fdf91670 <redacted> + 324
	11  Flutter                             0x0000000101242ff0 -[FlutterTextInputView setTextInputState:] + 580
	12  Flutter                             0x00000001012444e4 -[FlutterTextInputPlugin handleMethodCall:result:] + 340
	13  Flutter                             0x0000000101237688 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 128
	14  Flutter                             0x0000000101251530 _ZNK5shell21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrIN5blink15PlatformMessageEEE + 224
	15  Flutter                             0x0000000101253164 _ZN5shell23HeadlessPlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrIN5blink15PlatformMessageEEE + 40
	16  Flutter                             0x00000001012a39fc _ZNSt3__110__function6__funcIZN5shell5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrIN5blink15PlatformMessageEEEE4$_26NS_9allocatorIS9_EEFvvEEclEv + 80
	17  Flutter                             0x000000010125ff88 _ZN3fml15MessageLoopImpl15RunExpiredTasksEv + 824
	18  Flutter                             0x0000000101262f90 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 32
	19  CoreFoundation                      0x00000001d1b2dbf0 <redacted> + 28
	20  CoreFoundation                      0x00000001d1b2d920 <redacted> + 864
	21  CoreFoundation                      0x00000001d1b2d154 <redacted> + 248
	22  CoreFoundation                      0x00000001d1b28030 <redacted> + 1880
	23  CoreFoundation                      0x00000001d1b275b8 CFRunLoopRunSpecific + 436
	24  GraphicsServices                    0x00000001d3d9b584 GSEventRunModal + 100
	25  UIKitCore                           0x00000001fe167558 UIApplicationMain + 212
	26  Runner                              0x00000001009a3430 main + 124
	27  libdyld.dylib                       0x00000001d15e7b94 <redacted> + 4
)

@z2228391
Copy link

I had the same problem, is any way to solve this issue?

@HipSze
Copy link
Author

HipSze commented Oct 15, 2018

I had the same problem, is any way to solve this issue?

You can dismiss the keyboard when you type in other TextField. But, it is so stupid. I hope flutter or iOS 12 can fix this bug. It is big problem because I need to put my app to App Store.

@naro143
Copy link

naro143 commented Oct 21, 2018

Problem crashing with Japanese, CJK input to TextField, TextFormField.
To fix it we need to change attribute "autocorrect" of TextField, TextFormField to "false".

@eseidelGoogle
Copy link
Contributor

@cbracken would know how to get this fix. FYI @xster

@eseidelGoogle eseidelGoogle added the c: crash Stack traces logged to the console label Oct 24, 2018
@cbracken cbracken self-assigned this Oct 24, 2018
@lichentao
Copy link

image
ME TOO how to Resulation

@tubzby
Copy link

tubzby commented Nov 2, 2018

same crash here, received so much crash report when we switch some page to flutter recently.

`

CoreFoundation ___exceptionPreprocess + 228
1 libobjc.A.dylib objc_exception_throw + 56
2 CoreFoundation -[NSCache init]
3 CoreFoundation -[__NSCFString substringWithRange:] + 168
4 UIKitCore -[UIKeyboardImpl hasMarkedText] + 144
5 UIKitCore ___43-[UIKeyboardImpl generateAutofillCandidate]_block_invoke + 60
6 UIKitCore -[UIKeyboardTaskEntry execute:] + 200
7 UIKitCore -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 384
8 UIKitCore -[UIKeyboardTaskQueue performTask:] + 136
9 UIKitCore -[UIKeyboardImpl generateAutofillCandidate] + 136
10 UIKitCore -[UIKeyboardImpl selectionDidChange:] + 324
11 Flutter 0x0000000106c70000 + 88804
12 Flutter 0x0000000106c70000 + 94168
13 Flutter 0x0000000106c70000 + 40360
14 Flutter 0x0000000106c70000 + 154420
15 Flutter 0x0000000106c70000 + 403644
16 Flutter 0x0000000106c70000 + 203352
17 Flutter 0x0000000106c70000 + 208228
18 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 28
19 CoreFoundation ___CFRunLoopDoTimer + 864
20 CoreFoundation ___CFRunLoopDoTimers + 248
21 CoreFoundation ___CFRunLoopRun + 1880
22 CoreFoundation CFRunLoopRunSpecific + 436
23 GraphicsServices GSEventRunModal + 100
24 UIKitCore UIApplicationMain + 212

`

khiet pushed a commit to khiet/friendlychat that referenced this issue Nov 10, 2018
khiet pushed a commit to khiet/hchat-flutter that referenced this issue Nov 14, 2018
@cbracken
Copy link
Member

cbracken commented Dec 20, 2018

This should be fixed by flutter/engine#6989. Please update/open a new bug if you're still seeing this crash.

@dshukertjr
Copy link

This is still happening to me, but is it merged to the stable branch yet?

@repletetop
Copy link

同样问题,
error msg:
2019-10-01 11:12:08.460624+0800 Runner[18816:113195] *** -[__NSCFString substringWithRange:]: Range {2, 18446744073709551614} out of bounds; string length 2. This will become an exception for apps linked after 10.10 and iOS 8. Warning shown once per app execution.
2019-10-01 11:12:08.467880+0800 Runner[18816:113490] [general] __CFRunLoopModeFindSourceForMachPort returned NULL for mode 'kCFRunLoopDefaultMode' livePort: 25859

@chenyun122
Copy link

chenyun122 commented Aug 19, 2020

The cause of this crash: UItextField.markedTextRange is not used for calculating the Chinese(and Japanese etc) string's range and length.
Suggest Flutter TextField developer use following mechanism for checking maxLength:

if let selectedRange = textField.markedTextRange  {
    let position = textField.position(from: selectedRange.start, offset: 0)
    if position != nil { // means Chinese Pinyin(or Japanese) is inputting
        return  //stop doing calculating which will cause the crash
    }
}

// maxLength calculating here

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: internationalization Supporting other languages or locales. (aka i18n) a: text input Entering text in a text field or keyboard related problems c: crash Stack traces logged to the console engine flutter/engine repository. See also e: labels. platform-ios iOS applications specifically
Projects
None yet
Development

No branches or pull requests