Skip to content

hasSize assertion fail in SelectableRegion within a background page #119776

Description

@alexeyinkin

Steps to Reproduce

  1. Create a new Flutter project.
  2. Replace main.dart with the following.
  3. Run in Chrome.

Expected results: "foreground" text is visible, no exceptions

Actual results: "foreground" text is visible, two exceptions in console:

======== Exception caught by foundation library ====================================================
The following assertion was thrown while dispatching notifications for _SelectableRegionContainerDelegate:
Assertion failed: file:///home/alexey/snap/flutter/common/flutter/packages/flutter/lib/src/rendering/box.dart:2009:12
hasSize
"RenderBox was not laid out: RenderPhysicalModel#4cdfc NEEDS-LAYOUT NEEDS-PAINT"

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/rendering/box.dart 2009:12                               get size
packages/flutter/src/widgets/selection_container.dart 311:15                  get containerSize
packages/flutter/src/widgets/selectable_region.dart 1775:39                   [_updateHandleLayersAndOwners]
packages/flutter/src/widgets/selectable_region.dart 1761:5                    pushHandleLayers
packages/flutter/src/widgets/selection_container.dart 175:12                  pushHandleLayers
packages/flutter/src/widgets/selectable_region.dart 1124:5                    add
packages/flutter/src/rendering/selection.dart 195:7                           [_updateSelectionRegistrarSubscription]
packages/flutter/src/foundation/change_notifier.dart 381:24                   notifyListeners
packages/flutter/src/widgets/selectable_region.dart 1585:7                    [_updateSelectionGeometry]
packages/flutter/src/widgets/selectable_region.dart 1570:5                    didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1414:11                   didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1502:5                    [_updateSelectables]
packages/flutter/src/widgets/selectable_region.dart 1492:9                    <fn>
packages/flutter/src/scheduler/binding.dart 1289:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1227:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 942:7                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback
The _SelectableRegionContainerDelegate sending notification was: Instance of '_SelectableRegionContainerDelegate'
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Assertion failed: file:///home/alexey/snap/flutter/common/flutter/packages/flutter/lib/src/rendering/box.dart:2009:12
hasSize
"RenderBox was not laid out: RenderPhysicalModel#4cdfc NEEDS-LAYOUT NEEDS-PAINT"

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49  throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3    assertFailed
packages/flutter/src/rendering/box.dart 2009:12                               get size
packages/flutter/src/widgets/selection_container.dart 311:15                  get containerSize
packages/flutter/src/widgets/selectable_region.dart 1775:39                   [_updateHandleLayersAndOwners]
packages/flutter/src/widgets/selectable_region.dart 1587:5                    [_updateSelectionGeometry]
packages/flutter/src/widgets/selectable_region.dart 1570:5                    didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1414:11                   didChangeSelectables
packages/flutter/src/widgets/selectable_region.dart 1502:5                    [_updateSelectables]
packages/flutter/src/widgets/selectable_region.dart 1492:9                    <fn>
packages/flutter/src/scheduler/binding.dart 1289:15                           [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1227:9                            handleDrawFrame
packages/flutter/src/scheduler/binding.dart 942:7                             <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/isolate_helper.dart 48:19       internalCallback
====================================================================================================

The exception is only thrown if the page with SelectableRegion is in the background. If the foreground page is deleted, everything works fine.

main.dart
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: BackgroundSelectableRegionPage(),
    );
  }
}

final _focusNode = FocusNode();

class BackgroundSelectableRegionPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Navigator(
      pages: [
        MaterialPage(
          child: SelectableRegion(
            focusNode: _focusNode,
            selectionControls: materialTextSelectionControls,
            child: Scaffold(body: Text('background')),
          ),
        ),
        MaterialPage(
          child: Scaffold(body: Text('foreground')),
        ),
      ],
      onPopPage: (_, __) => false,
    );
  }
}
flutter doctor -v
[✓] Flutter (Channel stable, 3.7.1, on Ubuntu 20.04.5 LTS 5.14.0-1056-oem, locale en_US.UTF-8)
    • Flutter version 3.7.1 on channel stable at /home/alexey/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7048ed95a5 (9 hours ago), 2023-02-01 09:07:31 -0800
    • Engine revision 800594f1f4
    • Dart version 2.19.1
    • DevTools version 2.20.1

[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /home/alexey/Android/Sdk
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.2)
    • Android Studio at /home/alexey/bin/android-studio
    • Flutter plugin version 71.0.2
    • Dart plugin version 212.5744
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.74.3)
    • VS Code at /usr/share/code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 20.04.5 LTS 5.14.0-1056-oem
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Activity

  1. danagbemava-nc commented on Feb 2, 2023

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    As reported above, the bug does not reproduce when you remove/comment out the foreground widget and its enclosing MaterialPage.

    Labeling for further investigation.

    updated sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          home: BackgroundSelectableRegionPage(),
        );
      }
    }
    
    final _focusNode = FocusNode();
    
    class BackgroundSelectableRegionPage extends StatelessWidget {
      const BackgroundSelectableRegionPage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return Navigator(
          pages: [
            MaterialPage(
              child: SelectableRegion(
                focusNode: _focusNode,
                selectionControls: materialTextSelectionControls,
                child: const Scaffold(body: Text('background')),
              ),
            ),
            // const MaterialPage(
            //   child: Scaffold(body: Text('foreground')),
            // ), // uncomment this and hot restart to reproduce the error
          ],
          onPopPage: (_, __) => false,
        );
      }
    }
    logs
    Launching lib/main.dart on iPhone 14 Pro Max in debug mode...
    Xcode build done.                                           17.1s
    Connecting to VM Service at ws://127.0.0.1:58519/u-CI_kw-lvQ=/ws
    
    ════════ Exception caught by foundation library ════════════════════════════════
    The following assertion was thrown while dispatching notifications for _SelectableRegionContainerDelegate:
    RenderBox was not laid out: RenderPhysicalModel#d4ff8 NEEDS-LAYOUT NEEDS-PAINT
    'package:flutter/src/rendering/box.dart':
    Failed assertion: line 1966 pos 12: 'hasSize'
    
    
    Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
    In either case, please report this assertion by filing a bug on GitHub:
      https://github.com/flutter/flutter/issues/new?template=2_bug.md
    
    When the exception was thrown, this was the stack
    #2      RenderBox.size
    #3      SelectionContainerDelegate.containerSize
    #4      MultiSelectableSelectionContainerDelegate._updateHandleLayersAndOwners
    #5      MultiSelectableSelectionContainerDelegate.pushHandleLayers
    #6      _SelectionContainerState.pushHandleLayers
    #7      SelectableRegionState.add
    #8      SelectionRegistrant._updateSelectionRegistrarSubscription
    #9      ChangeNotifier.notifyListeners
    #10     MultiSelectableSelectionContainerDelegate._updateSelectionGeometry
    #11     MultiSelectableSelectionContainerDelegate.didChangeSelectables
    #12     _SelectableRegionContainerDelegate.didChangeSelectables
    #13     MultiSelectableSelectionContainerDelegate._updateSelectables
    #14     MultiSelectableSelectionContainerDelegate._scheduleSelectableUpdate.<anonymous closure>
    #15     SchedulerBinding._invokeFrameCallback
    #16     SchedulerBinding.handleDrawFrame
    #17     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
    #21     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:192:26)
    (elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)
    The _SelectableRegionContainerDelegate sending notification was: Instance of '_SelectableRegionContainerDelegate'
    ════════════════════════════════════════════════════════════════════════════════
    
    ════════ Exception caught by scheduler library ═════════════════════════════════
    RenderBox was not laid out: RenderPhysicalModel#d4ff8 NEEDS-LAYOUT NEEDS-PAINT
    'package:flutter/src/rendering/box.dart':
    Failed assertion: line 1966 pos 12: 'hasSize'
    
    ════════════════════════════════════════════════════════════════════════════════
    Application finished.
    Exited
    
    
    flutter doctor -v
    [✓] Flutter (Channel stable, 3.7.1, on macOS 13.1 22C65 darwin-arm64, locale en-GB)
        • Flutter version 3.7.1 on channel stable at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 7048ed95a5 (15 hours ago), 2023-02-01 09:07:31 -0800
        • Engine revision 800594f1f4
        • Dart version 2.19.1
        • DevTools version 2.20.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14C18
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [!] Android Studio (version 2022.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [!] Android Studio (version 2022.1)
        • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
        • 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
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [✓] IntelliJ IDEA Community Edition (version 2022.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • 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.74.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.58.0
    
    [✓] Connected device (5 available)
        • Pixel 7 (mobile)           • adb-28291FDH2001SA-5Lv71w._adb-tls-connect._tcp. • android-arm64  • Android 13 (API 33)
        • M2007J20CG (mobile)        • adb-5dd3be00-17AYzd._adb-tls-connect._tcp.       • android-arm64  • Android 12 (API 31)
        • iPhone 14 Pro Max (mobile) • 70C93773-FBEC-4F48-B648-EE61E0D00BFB             • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
        • macOS (desktop)            • macos                                            • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
        • Chrome (web)               • chrome                                           • web-javascript • Google Chrome 109.0.5414.119
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 2 categories.
    
    [!] Flutter (Channel master, 3.8.0-1.0.pre.32, on macOS 13.1 22C65 darwin-arm64, locale en-GB)
        • Flutter version 3.8.0-1.0.pre.32 on channel master at /Users/nexus/dev/sdks/flutters
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutters. Consider adding /Users/nexus/dev/sdks/flutters/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f9daa9aac4 (5 hours ago), 2023-02-01 22:59:24 -0500
        • Engine revision 679c4b42e2
        • Dart version 3.0.0 (build 3.0.0-192.0.dev)
        • DevTools version 2.21.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.2)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14C18
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [!] Android Studio (version 2022.1)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [!] Android Studio (version 2022.1)
        • Android Studio at /Users/nexus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
        • 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
        ✗ Unable to find bundled Java version.
        • Try updating or re-installing Android Studio.
    
    [✓] IntelliJ IDEA Community Edition (version 2022.3.2)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • 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.74.3)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.58.0
    
    [✓] Connected device (5 available)
        • Pixel 7 (mobile)           • adb-28291FDH2001SA-5Lv71w._adb-tls-connect._tcp. • android-arm64  • Android 13 (API 33)
        • M2007J20CG (mobile)        • adb-5dd3be00-17AYzd._adb-tls-connect._tcp.       • android-arm64  • Android 12 (API 31)
        • iPhone 14 Pro Max (mobile) • 70C93773-FBEC-4F48-B648-EE61E0D00BFB             • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
        • macOS (desktop)            • macos                                            • darwin-arm64   • macOS 13.1 22C65 darwin-arm64
        • Chrome (web)               • chrome                                           • web-javascript • Google Chrome 109.0.5414.119
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 3 categories.
    
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: routesNavigator, Router, and related APIs.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    f: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs
    c: crashStack traces logged to the console
    and removed
    in triagePresently being triaged by the triage team
    on Feb 2, 2023
  3. self-assigned this
    on Feb 6, 2023
  4. added
    r: fixedIssue is closed as already fixed in a newer version
    on Feb 7, 2023
  5. github-actions commented on Mar 3, 2023

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

  6. locked as resolved and limited conversation to collaborators on Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

c: crashStack traces logged to the consolef: routesNavigator, Router, and related APIs.f: selectionSelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIsfound in release: 3.7Found to occur in 3.7found in release: 3.8Found to occur in 3.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions