Skip to content

Fix debugNeedsPaint/Layout/CompositedLayerUpdate crashing in release mode#184627

Merged
auto-submit[bot] merged 7 commits into
flutter:masterfrom
realmeylisdev:fix/183696-debug-getters-release-crash
Apr 27, 2026
Merged

Fix debugNeedsPaint/Layout/CompositedLayerUpdate crashing in release mode#184627
auto-submit[bot] merged 7 commits into
flutter:masterfrom
realmeylisdev:fix/183696-debug-getters-release-crash

Conversation

@realmeylisdev

Copy link
Copy Markdown
Contributor

Summary

  • debugNeedsPaint, debugNeedsLayout, and debugNeedsCompositedLayerUpdate use a late variable inside an assert() closure, which means the variable is never initialized in release mode — causing a LateInitializationError crash when accessed
  • Replace the late + assert pattern with an explicit kReleaseMode check that returns false in release builds, matching the documented intent

Changes

  • packages/flutter/lib/src/rendering/object.dart: Updated all 3 debug getters to use kReleaseMode guard instead of late+assert pattern
  • Updated doc comments to say "Always returns false in release builds" instead of "In release builds, this throws"

Fixes #183696

…mode

Replace the legacy `late bool result` + `assert()` pattern with an explicit
`kReleaseMode` guard, matching the existing `debugNeedsSemanticsUpdate` getter
in the same class. The old pattern caused LateInitializationError in release
builds because Dart strips assert() blocks.

Fixes flutter#183696
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies RenderObject to return false for debugNeedsLayout, debugNeedsPaint, and debugNeedsCompositedLayerUpdate in release builds, replacing the previous behavior that would throw when asserts were disabled. The review feedback recommends using !kDebugMode instead of kReleaseMode to ensure consistent behavior in both profile and release modes and suggests updating the documentation to reflect that these properties return false in all non-debug builds.

Comment on lines +2525 to +2532
/// out and painted. Always returns false in release builds.
///
/// It is intended to be used by tests and asserts.
bool get debugNeedsLayout {
late bool result;
assert(() {
result = _needsLayout;
return true;
}());
return result;
if (kReleaseMode) {
return false;
}
return _needsLayout;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using kReleaseMode only handles the release build case. However, since assert blocks are also disabled in profile mode, the original implementation would have crashed there as well. To ensure consistent behavior across all non-debug builds (Profile and Release) and to follow the convention for debug* properties, consider using !kDebugMode instead. This ensures the property returns false in both profile and release modes, and the documentation should be updated to reflect this.

  /// out and painted. Always returns false in non-debug builds.
  ///
  /// It is intended to be used by tests and asserts.
  bool get debugNeedsLayout {
    if (!kDebugMode) {
      return false;
    }
    return _needsLayout;
References
  1. Code should follow the guidance and principles described in the Flutter contribution guide, which includes doing things right for all build modes. (link)

/// to condition their runtime behavior on whether they are dirty or not,
/// since they should only be marked dirty immediately prior to being laid
/// out and painted. (In release builds, this throws.)
/// out and painted. Always returns false in release builds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the implementation is changed to use !kDebugMode, the documentation should be updated to reflect that it returns false in all non-debug builds (including profile mode).

  /// out and painted. Always returns false in non-debug builds.

Comment on lines +3275 to +3278
if (kReleaseMode) {
return false;
}
return _needsPaint;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using !kDebugMode instead of kReleaseMode to ensure consistent behavior in both Profile and Release modes, as assert statements are disabled in both. This also aligns with the naming convention for debug* properties.

    if (!kDebugMode) {
      return false;
    }
    return _needsPaint;

Comment on lines +3288 to +3295
/// out and painted. Always returns false in release builds.
///
/// It is intended to be used by tests and asserts.
bool get debugNeedsCompositedLayerUpdate {
late bool result;
assert(() {
result = _needsCompositedLayerUpdate;
return true;
}());
return result;
if (kReleaseMode) {
return false;
}
return _needsCompositedLayerUpdate;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other debug properties, using !kDebugMode is preferred over kReleaseMode to provide consistent behavior across all non-debug builds (Profile and Release) and to match the updated documentation.

  /// out and painted. Always returns false in non-debug builds.
  ///
  /// It is intended to be used by tests and asserts.
  bool get debugNeedsCompositedLayerUpdate {
    if (!kDebugMode) {
      return false;
    }
    return _needsCompositedLayerUpdate;

realmeylisdev and others added 2 commits April 6, 2026 11:10
- Use !kDebugMode to cover both profile and release modes, since
  asserts are disabled in both
- Update doc comments to say "non-debug builds" instead of "release builds"
@justinmc
justinmc requested a review from Piinks April 7, 2026 22:27
@Piinks

Piinks commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

These are not meant to be called in release mode. I wonder if the fix is in the other direction, fixing the places where this pattern is not honored. I need to look into the other cases where tis has been allowed.

@futpib

futpib commented Apr 8, 2026

Copy link
Copy Markdown

Check this out, I tried a similar PR, landed an a linter instead #183697

@Piinks

Piinks commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Touching base with @chunhtai about this, I see the issue references how debugNeedsSemanticsUpdate works, which was introduced in https://github.com/flutter/flutter/pull/151688/files

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caught up with @chunhtai on this, we both agree that debug method is ok to be called outside of debug mode, but they won't return meaningful result. I think this LGTM as it aligns with debugNeedsSemanticsUpdate, and we are looking into comprehensive lint coverage in #185091
Thanks for you patience while I double checked this.

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chunhtai chunhtai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chunhtai chunhtai added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Apr 15, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 15, 2026
@auto-submit

auto-submit Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/184627, because - The status or check suite Windows framework_tests_libraries has failed. Please fix the issues identified (or deflake) before re-applying this label.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 15, 2026
@Piinks Piinks added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Apr 27, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Apr 27, 2026
Merged via the queue into flutter:master with commit 7ff3059 Apr 27, 2026
87 of 88 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 27, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 28, 2026
…11595)

Manual roll Flutter from 31001886cbe8 to 61fca76dd523 (53 revisions)

Manual roll requested by [email protected]

flutter/flutter@3100188...61fca76

2026-04-27 [email protected] Adds integration test for the FLTEnableSDFs flag for iOS (flutter/flutter#185637)
2026-04-27 [email protected] Fix sdfs being enabled for MacOS regardless of FLTEnableSDFs value (flutter/flutter#185565)
2026-04-27 [email protected] Don't use UberSDF for paint with incompatible blend modes (flutter/flutter#184889)
2026-04-27 [email protected] Roll Dart SDK from de495e3de9a0 to 941ca325cfc9 (2 revisions) (flutter/flutter#185653)
2026-04-27 [email protected] [a11y] Add CONTENT_CHANGE_TYPE_EXPANDED support on android. (flutter/flutter#185305)
2026-04-27 [email protected] Roll pub packages (flutter/flutter#185641)
2026-04-27 [email protected] Modify analyze.dart to have flags to run only or exclude each verification step.  (flutter/flutter#185618)
2026-04-27 [email protected] Fix debugNeedsPaint/Layout/CompositedLayerUpdate crashing in release mode (flutter/flutter#184627)
2026-04-27 [email protected] Enable `var_with_no_type_annotation` lint. (flutter/flutter#185215)
2026-04-27 [email protected] Fix SelectionArea handles overlapping context menu on Android (flutter/flutter#182663)
2026-04-27 [email protected] Adds debugging information to compiled metal shaders (flutter/flutter#185629)
2026-04-27 [email protected] Roll pub packages (flutter/flutter#185638)
2026-04-27 [email protected] Use null-aware elements in dev/devicelab/lib/framework/browser.dart (flutter/flutter#184778)
2026-04-27 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#185633)
2026-04-27 [email protected] Added useOriginalColors flag which allows ImageIcon to bypass IconTheme colorization and use the original colors (flutter/flutter#180491)
2026-04-27 [email protected] Roll Packages from 8400f71 to 23280da (2 revisions) (flutter/flutter#185619)
2026-04-27 [email protected] Roll Skia from f1238e0f1022 to ce82d32b3e03 (1 revision) (flutter/flutter#185616)
2026-04-27 [email protected] [SwiftPM] Enable package resolution on xcodebuild commands (flutter/flutter#185208)
2026-04-27 [email protected] [iOS] Refactor keyboard inset logic into FlutterKeyboardInsetManager (flutter/flutter#185535)
2026-04-27 [email protected] [Win32] FlutterDesktopEngineGetGraphicsAdapter should use out parameter (flutter/flutter#185590)
2026-04-27 [email protected] Roll Skia from d77e3356d526 to f1238e0f1022 (4 revisions) (flutter/flutter#185604)
2026-04-27 [email protected] Roll Fuchsia Linux SDK from flsn8jC4LkTn6WECf... to i6d0NoDueUiXpePfX... (flutter/flutter#185601)
2026-04-26 [email protected] Roll Dart SDK from a108dfe2d227 to de495e3de9a0 (1 revision) (flutter/flutter#185599)
2026-04-26 [email protected] Roll Skia from ce9aa2231292 to d77e3356d526 (1 revision) (flutter/flutter#185596)
2026-04-26 [email protected] Roll Skia from 622fff4c24d2 to ce9aa2231292 (1 revision) (flutter/flutter#185588)
2026-04-25 [email protected] Roll Fuchsia Linux SDK from 9fPnyEo9PaNdXtasl... to flsn8jC4LkTn6WECf... (flutter/flutter#185585)
2026-04-25 [email protected] Roll Dart SDK from 605a8faf0dda to a108dfe2d227 (1 revision) (flutter/flutter#185584)
2026-04-25 [email protected] Roll Dart SDK from 6b8c39765f17 to 605a8faf0dda (1 revision) (flutter/flutter#185578)
2026-04-25 [email protected] Roll Skia from 185f6b57d64f to 622fff4c24d2 (1 revision) (flutter/flutter#185573)
2026-04-25 [email protected] Implement square-like round superellipses with circular corners in the SDF uber shader (flutter/flutter#185370)
2026-04-25 [email protected] Add @awaitNotRequired annotation to flutter sdk (flutter/flutter#181513)
2026-04-25 [email protected] Roll Dart SDK from 01228cb7af42 to 6b8c39765f17 (2 revisions) (flutter/flutter#185569)
2026-04-25 [email protected] Adapt the DisplayList benchmarks into a primitive rendering benchmark suite (flutter/flutter#185270)
2026-04-25 [email protected] Enable SPM for GoogleMobileAds (flutter/flutter#185548)
2026-04-25 [email protected] Roll Skia from 3f467a581942 to 185f6b57d64f (1 revision) (flutter/flutter#185564)
2026-04-25 [email protected] Fix Table crash when a cell child paints below the row bottom (flutter/flutter#185323)
2026-04-24 [email protected] Make sure that an Image doesn't crash in 0x0 environment (flutter/flutter#181154)
2026-04-24 [email protected] Roll Skia from 300d432048b0 to 3f467a581942 (3 revisions) (flutter/flutter#185558)
2026-04-24 [email protected] Roll Dart SDK from c26627715892 to 01228cb7af42 (4 revisions) (flutter/flutter#185559)
2026-04-24 [email protected] Reland "[web] Fix LateInitializationError in CkSurface and SkwasmSurface (#185116)" (flutter/flutter#185553)
2026-04-24 [email protected] [github]fix git ls-file glob pattern in labeler.yml instruction (flutter/flutter#185495)
2026-04-24 [email protected] [ios]update ios-reviewers tags to include more files (flutter/flutter#185490)
2026-04-24 [email protected] Add initial support for Cross-Origin Storage (flutter/flutter#184149)
2026-04-24 [email protected] tool: Skip cached engine artifacts with local engine (flutter/flutter#185546)
...
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…lutter#11595)

Manual roll Flutter from 31001886cbe8 to 61fca76dd523 (53 revisions)

Manual roll requested by [email protected]

flutter/flutter@3100188...61fca76

2026-04-27 [email protected] Adds integration test for the FLTEnableSDFs flag for iOS (flutter/flutter#185637)
2026-04-27 [email protected] Fix sdfs being enabled for MacOS regardless of FLTEnableSDFs value (flutter/flutter#185565)
2026-04-27 [email protected] Don't use UberSDF for paint with incompatible blend modes (flutter/flutter#184889)
2026-04-27 [email protected] Roll Dart SDK from de495e3de9a0 to 941ca325cfc9 (2 revisions) (flutter/flutter#185653)
2026-04-27 [email protected] [a11y] Add CONTENT_CHANGE_TYPE_EXPANDED support on android. (flutter/flutter#185305)
2026-04-27 [email protected] Roll pub packages (flutter/flutter#185641)
2026-04-27 [email protected] Modify analyze.dart to have flags to run only or exclude each verification step.  (flutter/flutter#185618)
2026-04-27 [email protected] Fix debugNeedsPaint/Layout/CompositedLayerUpdate crashing in release mode (flutter/flutter#184627)
2026-04-27 [email protected] Enable `var_with_no_type_annotation` lint. (flutter/flutter#185215)
2026-04-27 [email protected] Fix SelectionArea handles overlapping context menu on Android (flutter/flutter#182663)
2026-04-27 [email protected] Adds debugging information to compiled metal shaders (flutter/flutter#185629)
2026-04-27 [email protected] Roll pub packages (flutter/flutter#185638)
2026-04-27 [email protected] Use null-aware elements in dev/devicelab/lib/framework/browser.dart (flutter/flutter#184778)
2026-04-27 [email protected] Sync CHANGELOG.md from stable (flutter/flutter#185633)
2026-04-27 [email protected] Added useOriginalColors flag which allows ImageIcon to bypass IconTheme colorization and use the original colors (flutter/flutter#180491)
2026-04-27 [email protected] Roll Packages from 8400f71 to 23280da (2 revisions) (flutter/flutter#185619)
2026-04-27 [email protected] Roll Skia from f1238e0f1022 to ce82d32b3e03 (1 revision) (flutter/flutter#185616)
2026-04-27 [email protected] [SwiftPM] Enable package resolution on xcodebuild commands (flutter/flutter#185208)
2026-04-27 [email protected] [iOS] Refactor keyboard inset logic into FlutterKeyboardInsetManager (flutter/flutter#185535)
2026-04-27 [email protected] [Win32] FlutterDesktopEngineGetGraphicsAdapter should use out parameter (flutter/flutter#185590)
2026-04-27 [email protected] Roll Skia from d77e3356d526 to f1238e0f1022 (4 revisions) (flutter/flutter#185604)
2026-04-27 [email protected] Roll Fuchsia Linux SDK from flsn8jC4LkTn6WECf... to i6d0NoDueUiXpePfX... (flutter/flutter#185601)
2026-04-26 [email protected] Roll Dart SDK from a108dfe2d227 to de495e3de9a0 (1 revision) (flutter/flutter#185599)
2026-04-26 [email protected] Roll Skia from ce9aa2231292 to d77e3356d526 (1 revision) (flutter/flutter#185596)
2026-04-26 [email protected] Roll Skia from 622fff4c24d2 to ce9aa2231292 (1 revision) (flutter/flutter#185588)
2026-04-25 [email protected] Roll Fuchsia Linux SDK from 9fPnyEo9PaNdXtasl... to flsn8jC4LkTn6WECf... (flutter/flutter#185585)
2026-04-25 [email protected] Roll Dart SDK from 605a8faf0dda to a108dfe2d227 (1 revision) (flutter/flutter#185584)
2026-04-25 [email protected] Roll Dart SDK from 6b8c39765f17 to 605a8faf0dda (1 revision) (flutter/flutter#185578)
2026-04-25 [email protected] Roll Skia from 185f6b57d64f to 622fff4c24d2 (1 revision) (flutter/flutter#185573)
2026-04-25 [email protected] Implement square-like round superellipses with circular corners in the SDF uber shader (flutter/flutter#185370)
2026-04-25 [email protected] Add @awaitNotRequired annotation to flutter sdk (flutter/flutter#181513)
2026-04-25 [email protected] Roll Dart SDK from 01228cb7af42 to 6b8c39765f17 (2 revisions) (flutter/flutter#185569)
2026-04-25 [email protected] Adapt the DisplayList benchmarks into a primitive rendering benchmark suite (flutter/flutter#185270)
2026-04-25 [email protected] Enable SPM for GoogleMobileAds (flutter/flutter#185548)
2026-04-25 [email protected] Roll Skia from 3f467a581942 to 185f6b57d64f (1 revision) (flutter/flutter#185564)
2026-04-25 [email protected] Fix Table crash when a cell child paints below the row bottom (flutter/flutter#185323)
2026-04-24 [email protected] Make sure that an Image doesn't crash in 0x0 environment (flutter/flutter#181154)
2026-04-24 [email protected] Roll Skia from 300d432048b0 to 3f467a581942 (3 revisions) (flutter/flutter#185558)
2026-04-24 [email protected] Roll Dart SDK from c26627715892 to 01228cb7af42 (4 revisions) (flutter/flutter#185559)
2026-04-24 [email protected] Reland "[web] Fix LateInitializationError in CkSurface and SkwasmSurface (#185116)" (flutter/flutter#185553)
2026-04-24 [email protected] [github]fix git ls-file glob pattern in labeler.yml instruction (flutter/flutter#185495)
2026-04-24 [email protected] [ios]update ios-reviewers tags to include more files (flutter/flutter#185490)
2026-04-24 [email protected] Add initial support for Cross-Origin Storage (flutter/flutter#184149)
2026-04-24 [email protected] tool: Skip cached engine artifacts with local engine (flutter/flutter#185546)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: debugNeedsPaint, debugNeedsLayout, debugNeedsCompositedLayerUpdate crash in release mode instead of returning gracefully

5 participants