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

SelectionArea crashes with debugNeedsLayout is not true #125065

Closed
2 tasks done
chunhtai opened this issue Apr 18, 2023 · 2 comments · Fixed by #125140
Closed
2 tasks done

SelectionArea crashes with debugNeedsLayout is not true #125065

chunhtai opened this issue Apr 18, 2023 · 2 comments · Fixed by #125140
Assignees
Labels
c: crash Stack traces logged to the console c: regression It was better in the past than it is now f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels. P1 High-priority issues at the top of the work list

Comments

@chunhtai
Copy link
Contributor

Is there an existing issue for this?

Steps to reproduce

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light().copyWith(
        useMaterial3: true,
      ),
      debugShowCheckedModeBanner: false,
      home: const Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  const MyWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return const SelectionArea(
      child: Column(
        children: <Widget>[
          Text('How are you?'),
          Text('Good, and you?'),
          Text('Fine, thank you.'),
        ],
      ),
    );
  }
}

app crashes upon flutter run

This is a regression caused by #124624

Actual results

app crashed

Logs

Logs
══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during a scheduler callback:
'package:flutter/src/rendering/paragraph.dart': Failed assertion: line 953 pos 12:
'!debugNeedsLayout': is not true.

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

When the exception was thrown, this was the stack:
#2      RenderParagraph.getBoxesForSelection (package:flutter/src/rendering/paragraph.dart:953:12)
#3      _SelectableFragment._rect (package:flutter/src/rendering/paragraph.dart:1759:45)
#4      _SelectableFragment.getTransformToParagraph (package:flutter/src/rendering/paragraph.dart:1733:38)
#5      _SelectableFragment.getTransformTo (package:flutter/src/rendering/paragraph.dart:1738:12)
#6      MultiSelectableSelectionContainerDelegate._compareScreenOrder (package:flutter/src/widgets/selectable_region.dart:1619:9)
#7      Sort._insertionSort (dart:_internal/sort.dart:69:36)
#8      Sort._doSort (dart:_internal/sort.dart:58:7)
#9      Sort.sort (dart:_internal/sort.dart:33:5)
#10     ListBase.sort (dart:collection/list.dart:321:10)
#11     MultiSelectableSelectionContainerDelegate._flushAdditions (package:flutter/src/widgets/selectable_region.dart:1526:70)
#12     MultiSelectableSelectionContainerDelegate._updateSelectables (package:flutter/src/widgets/selectable_region.dart:1520:7)
#13     MultiSelectableSelectionContainerDelegate._scheduleSelectableUpdate.<anonymous closure> (package:flutter/src/widgets/selectable_region.dart:1513:7)
#14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15)
#15     SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1141:11)
#16     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#17     SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1139:17)
#18     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:940:7)
#22     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)


This exception was thrown in the context of a scheduler callback. When the scheduler callback was _registered_ (as opposed to when the exception was thrown), this was the stack:
#2      SchedulerBinding.scheduleFrameCallback (package:flutter/src/scheduler/binding.dart:573:49)
#3      MultiSelectableSelectionContainerDelegate._scheduleSelectableUpdate (package:flutter/src/widgets/selectable_region.dart:1508:72)
#4      MultiSelectableSelectionContainerDelegate.add (package:flutter/src/widgets/selectable_region.dart:1490:5)
#5      List.forEach (dart:core-patch/growable_array.dart:416:8)
#6      RenderParagraph._updateSelectionRegistrarSubscription (package:flutter/src/rendering/paragraph.dart:205:31)
#7      RenderParagraph.registrar= (package:flutter/src/rendering/paragraph.dart:197:5)
#8      new RenderParagraph (package:flutter/src/rendering/paragraph.dart:110:10)
#9      RichText.createRenderObject (package:flutter/src/widgets/basic.dart:5833:12)
#10     RenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5932:52)
#11     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6577:11)
...     Normal element mounting (10 frames)
#21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#22     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#23     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (106 frames)
#129    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#130    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#131    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (324 frames)
#455    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#456    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6570:36)
#457    MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6582:32)
...     Normal element mounting (452 frames)
#909    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3971:16)
#910    Element.updateChild (package:flutter/src/widgets/framework.dart:3708:18)
#911    RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1240:16)
#912    RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:1209:5)
#913    RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:1156:18)
#914    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2720:19)
#915    RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:1155:13)
#916    WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:988:7)
#917    WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:968:7)
#921    _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
(elided 5 frames from class _FrameCallbackEntry, class _Timer, and dart:async-patch)
════════════════════════════════════════════════════════════════════════════════════════════════════

Flutter Doctor output

Doctor output
<!-- Paste your output here -->
@chunhtai chunhtai added c: regression It was better in the past than it is now c: crash Stack traces logged to the console framework flutter/packages/flutter repository. See also f: labels. f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs P1 High-priority issues at the top of the work list labels Apr 18, 2023
@chunhtai chunhtai self-assigned this Apr 18, 2023
@chunhtai
Copy link
Contributor Author

cc @Renzo-Olivares

auto-submit bot pushed a commit that referenced this issue Apr 19, 2023
…125140)

The regression was caused by the previous pr #124624 changes postframecallback to scheduleframecallback. The reason is that if a new postframecallback was scheduled when running a postframecallback. The newly added postframecallback will be execute on the next frame. However, adding postframecallback will not schedule a new frame. So if there isn't other widget that schedule a new frame, the newly added postframecallback will never gets run.

After changing to scheduleframecallback, it causes an issue that transient callback may be called when rendering tree contains dirty layout information that are waiting to be rebuilt.

Therefore, I use microtask to get around of the postframecallback issue instead of scheduleframecallback.

fixes #125065
@github-actions
Copy link

github-actions bot commented May 3, 2023

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 May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
c: crash Stack traces logged to the console c: regression It was better in the past than it is now f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels. P1 High-priority issues at the top of the work list
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant