Skip to content

RenderEditable.delete is racy #80226

Closed
Closed

Description

@nt4f04uNd

i suppose this was introduced in #79973

when framerate is low, spamming delete key may throw

note: example in code sample exaggerated to achieve low framerate on the emulator. on my redmi note 5 this happens all the time in debug mode even with much more trivial examples

logs
  ══╡ EXCEPTION CAUGHT BY SERVICES LIBRARY ╞══════════════════════════════════════════════════════════
The following RangeError was thrown during a platform message callback:
Value not in range: 7
When the exception was thrown, this was the stack:
#0      _StringBase.substring (dart:core-patch/string_patch.dart:399:7)
#1      TextRange.textBefore (dart:ui/text.dart:2750:17)
#2      RenderEditable.delete (package:flutter/src/rendering/editable.dart:1119:37)
#3      _DeleteTextAction.invoke (package:flutter/src/widgets/default_text_editing_actions.dart:88:45)
#4      ActionDispatcher.invokeAction (package:flutter/src/widgets/actions.dart:517:21)
#5      ShortcutManager.handleKeypress (package:flutter/src/widgets/shortcuts.dart:366:36)
#6      _ShortcutsState._handleOnKey (package:flutter/src/widgets/shortcuts.dart:708:20)
#7      FocusManager._handleRawKeyEvent (package:flutter/src/widgets/focus_manager.dart:1678:43)
#8      RawKeyboard._handleKeyEvent (package:flutter/src/services/raw_keyboard.dart:682:69)
#9      BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:73:49)
#10     BasicMessageChannel.setMessageHandler.<anonymous closure> (package:flutter/src/services/platform_channel.dart:72:47)
#11     _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:284:33)
#12     _invoke3.<anonymous closure> (dart:ui/hooks.dart:223:15)
#16     _invoke3 (dart:ui/hooks.dart:222:10)
#17     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:520:7)
#18     _dispatchPlatformMessage (dart:ui/hooks.dart:90:31)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════════════════════════
code sample
import 'dart:math';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<double> list;

  @override
  void initState() {
    super.initState();
    _update();
  }

  void _update() {
    setState(() {
      list = List.generate(10000, (index) => Random().nextDouble());
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'System nav back button bug',
      home: SafeArea(
        child: Scaffold(
          body: Center(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                TextField(
                  onChanged: (_) {
                    _update();
                  },
                ),
                Expanded(
                  child: ListView(
                    children: list
                        .map((el) => ListTile(title: Text(el.toString())))
                        .toList(),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel master, 2.1.0-13.0.pre.574, on Microsoft Windows [Version 10.0.19041.867], locale ru-RU)
    • Flutter version 2.1.0-13.0.pre.574 at c:\dev\src\flutter
    • Framework revision 02efffc134 (33 hours ago), 2021-04-10 03:49:01 -0400
    • Engine revision 8863afff16
    • Dart version 2.13.0 (build 2.13.0-222.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\danya\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.7.7)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.7.30621.155
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] IntelliJ IDEA Community Edition (version 2020.3)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.55.1)
    • VS Code at C:\Users\danya\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19041.867]
    • Chrome (web)            • chrome        • web-javascript • Google Chrome 89.0.4389.114
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 89.0.774.63

• No issues found!
video.mp4

Activity

  1. TahaTesser commented on Apr 12, 2021

    @TahaTesser
    Contributor

    Hi @nt4f04uNd
    Thanks for filing the issue, I can confirm it as regression

    flutter doctor -v
    [✓] Flutter (Channel master, 2.1.0-13.0.pre.574, on Microsoft Windows [Version 10.0.19042.870], locale en-US)
        • Flutter version 2.1.0-13.0.pre.574 at C:\Users\Taha\Code\flutter_master
        • Framework revision 02efffc134 (2 days ago), 2021-04-10 03:49:01 -0400
        • Engine revision 8863afff16
        • Dart version 2.13.0 (build 2.13.0-222.0.dev)
    
    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
        • Android SDK at C:\Users\Taha\Code\SDK
        • Platform android-30, build-tools 30.0.3
        • ANDROID_HOME = C:\Users\Taha\Code\SDK
        • Java binary at: C:\Users\Taha\Code\android-studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
        ✗ Android license status unknown.
          Run `flutter doctor --android-licenses` to accept the SDK licenses.
          See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
    
    [✓] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.2)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.9.31112.23
        • Windows 10 SDK version 10.0.19041.0
    
    [✓] Android Studio (version 4.1.0)
        • Android Studio at C:\Users\Taha\Code\android-studio
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.1)
        • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3
        • Flutter plugin version 55.0.5
        • Dart plugin version 211.6693.108
    
    [✓] VS Code (version 1.55.1)
        • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.21.0
    
    [✓] Connected device (4 available)
        • RMX2001 (mobile)  • EUYTFEUSQSRGDA6D • android-arm64  • Android 10 (API 29)
        • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19042.870]
        • Chrome (web)      • chrome           • web-javascript • Google Chrome 89.0.4389.114
        • Edge (web)        • edge             • web-javascript • Microsoft Edge 89.0.774.68
    
    ! Doctor found issues in 1 category.
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    c: regressionIt was better in the past than it is now
    and removed
    in triagePresently being triaged by the triage team
    on Apr 12, 2021
  3. nt4f04uNd commented on Apr 12, 2021

    @nt4f04uNd
    MemberAuthor
  4. added
    a: text inputEntering text in a text field or keyboard related problems
    on Apr 12, 2021
  5. HansMuller commented on Apr 12, 2021

    @HansMuller
    Contributor
  6. LongCatIsLooong commented on Apr 12, 2021

    @LongCatIsLooong
    Contributor

    This is a known issue (and predates #79973) I think.

    RenderEditable can't handle 2 key events well in the same frame. Reading the plain text (or the selection) from RenderEditable (which represents the TextEditingValue from the previous frame), and directly overwriting TextEditingController.value is dangerous.
    RenderEditable should probably never directly talk to the text editing controller.

    I'm considering exposing a widget that has a TextSpan builder (like what we have in TextEditingController) and an onChanged field (somewhat similar to _Editable but I think it would be nice to make it a public class), to avoid direct communication between the controller and RenderEditable, and also fill the missing link of TextSpan <=> TextEditingValue conversion.

  7. LongCatIsLooong commented on May 7, 2021

    @LongCatIsLooong
    Contributor

    Internal: b/187337775. Applying a quick fix to mitigate the problem.

  8. goderbauer commented on May 4, 2022

    @goderbauer
    Member

    @LongCatIsLooong Is this one fixed? Looks there have been some PRs submitted for this one.

  9. added
    P2Important issues not at the top of the work list
    on May 4, 2022
  10. LongCatIsLooong commented on May 4, 2022

    @LongCatIsLooong
    Contributor

    Looks like RenderEditable.delete is gone. I suspect we still have the same kind of problems in RenderEditable but we should be able to close this one.

  11. github-actions commented on May 19, 2022

    @github-actions

    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.

  12. locked as resolved and limited conversation to collaborators on May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsfound in release: 2.1Found to occur in 2.1frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: solvedIssue is closed as solved

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions