Skip to content

[iOS Keyboard] All flutter iOS applications crashes when pressing ESC key with an external keyboard (cmd+.) #106407

@dupuchba

Description

@dupuchba

Reproduce this bug :

  • 1/ download or create any flutter app, i.e. : Google Ad on iOS or an iPad with an external keyboard
  • 2/ press cmd+. (esc) on your external keyboard

Error :

*** Assertion failure in uint64_t (anonymous namespace)::GetLogicalKeyForEvent(FlutterUIPressProxy *, uint64_t)(), FlutterEmbedderKeyResponder.mm:173
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected long key label: |UIKeyInputEscape|.'

Hypothesis from src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.mm
For some reason the ESC key is not detected as a control character and goes through the NSCAssert with a keyLabelLength >=2 throwing an exception.
For some undocumented reason IsControlCharacter is false when length > 1
I don't have a fix because I could not run my custom engine on my device, I ran into multiple issues for the last 1,5 days...
I cannot run the tests either, I had this error

#include "flutter/testing/test_gl_surface.h"
          ^--------------------------------
It is not in any dependency of
  //flutter/shell/common:shell_unittests
The include file is in the target(s):
  //flutter/testing:opengl
which should somehow be reachable.
static uint64_t GetLogicalKeyForEvent(FlutterUIPressProxy* press, uint64_t physicalKey)
    API_AVAILABLE(ios(13.4)) {
  // Look to see if the keyCode can be mapped from keycode.
  auto fromKeyCode = keyCodeToLogicalKey.find(press.key.keyCode);
  if (fromKeyCode != keyCodeToLogicalKey.end()) {
    return fromKeyCode->second;
  }
  const char* characters =
      getEventCharacters(press.key.charactersIgnoringModifiers, press.key.keyCode);
  NSString* keyLabel =
      characters == nullptr ? nil : [[[NSString alloc] initWithUTF8String:characters] autorelease];
  NSUInteger keyLabelLength = [keyLabel length];
  // If this key is printable, generate the logical key from its Unicode
  // value. Control keys such as ESC, CTRL, and SHIFT are not printable. HOME,
  // DEL, arrow keys, and function keys are considered modifier function keys,
  // which generate invalid Unicode scalar values.
  if (keyLabelLength != 0 && !IsControlCharacter(keyLabelLength, keyLabel) &&
      !IsUnprintableKey(keyLabelLength, keyLabel)) {
    // Given that charactersIgnoringModifiers can contain a string of arbitrary
    // length, limit to a maximum of two Unicode scalar values. It is unlikely
    // that a keyboard would produce a code point bigger than 32 bits, but it is
    // still worth defending against this case.
    NSCAssert((keyLabelLength < 2), @"Unexpected long key label: |%@|.", keyLabel);

    uint64_t codeUnit = (uint64_t)[keyLabel characterAtIndex:0];
    if (keyLabelLength == 2) {
      uint64_t secondCode = (uint64_t)[keyLabel characterAtIndex:1];
      codeUnit = (codeUnit << 16) | secondCode;
    }
    return KeyOfPlane(toLower(codeUnit), kUnicodePlane);
  }

  // This is a non-printable key that is unrecognized, so a new code is minted
  // with the autogenerated bit set.
  return KeyOfPlane(press.key.keyCode, kIosPlane);
}

The inconvenience is quite problematic for us as we are trying to port a text editor whose userbase is reliant on cmd+. as a shortcut

Metadata

Metadata

Assignees

Labels

P0Critical issues such as a build break or regressionc: crashStack traces logged to the consoleengineflutter/engine related. See also e: labels.found in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-iosiOS applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions