Skip to content

Tolerate floating-point rounding in paintImage centerSlice assertion - #185789

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
gabrimatic:paint-image-center-slice-precision
Aug 26, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:masterfrom
gabrimatic:paint-image-center-slice-precision

Conversation

@gabrimatic

@gabrimatic gabrimatic commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

paintImage uses a strict == comparison between sourceSize and inputSize to verify that the chosen BoxFit does not drop image pixels when centerSlice is set. The check has two failure modes that aren't actually bugs in the caller:

  1. When the image's pixel dimensions are not evenly divisible by scale, the inputSize / scale * scale round trip lands a few ULPs away from the original inputSize. The assertion fires under strict equality even though the math is correct.
  2. When the destination rect is too small to fit the centerSlice borders, outputSize becomes non-positive and applyBoxFit short-circuits to Size.zero. The assertion then compares (0,0) against the inner-input size and fires for a reason unrelated to what it is meant to catch (this is the configuration in the linked issue's repro).

This change:

  • Compares with precisionErrorTolerance instead of ==, absorbing the FP rounding.
  • Skips the assertion entirely when the centerSlice borders can't fit the destination rect (so the assertion no longer fires for the degenerate case it wasn't designed to police).

The original safety check — that the chosen BoxFit didn't shrink the source — is preserved for the cases it was meant to catch.

Test plan

  • Added centerSlice tolerates floating-point rounding when scale divides unevenly — exercises the FP-tolerance path with a destination rect large enough to enclose the borders.
  • Added centerSlice does not throw when the destination rect is smaller than the slice borders — reproduces the exact configuration in the linked issue (208×142 image, scale 3, 1×1 centerSlice into a 100×46 rect) which previously failed the assertion.
  • flutter test packages/flutter/test/painting/paint_image_test.dart — all tests pass.
  • flutter test packages/flutter/test/painting/decoration_test.dart packages/flutter/test/rendering/image_test.dart — pass.
  • flutter analyze — no issues on the changed files.

Fixes #27827

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Apr 29, 2026
@gabrimatic
gabrimatic force-pushed the paint-image-center-slice-precision branch from 2655169 to 952e842 Compare April 29, 2026 22:12

@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 updates the paintImage function in decoration_image.dart to use precisionErrorTolerance when asserting that the source size matches the input size, which prevents failures caused by floating-point rounding errors when image dimensions are not evenly divisible by the scale. It also introduces a sliceFits boolean to ensure these assertions only run when the destination rectangle is large enough to accommodate the centerSlice borders. Corresponding regression tests have been added to paint_image_test.dart. Feedback was provided to refactor the assertion logic for improved readability by extracting the size difference calculation.

Comment thread packages/flutter/lib/src/painting/decoration_image.dart
@gabrimatic
gabrimatic force-pushed the paint-image-center-slice-precision branch 5 times, most recently from f3d4764 to 11f3e08 Compare May 2, 2026 09:07
@justinmc
justinmc self-requested a review May 5, 2026 22:45

@justinmc justinmc 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 👍

Thank you for fixing this old issue!

@justinmc justinmc added the CICD Run CI/CD label Jul 28, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 24, 2026
@AbdeMohlbi AbdeMohlbi added the CICD Run CI/CD label Aug 24, 2026
@justinmc
justinmc force-pushed the paint-image-center-slice-precision branch from 2157673 to a6426e9 Compare August 24, 2026 22:05
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 24, 2026
@justinmc

Copy link
Copy Markdown
Contributor

Rebasing to try to kick the Google tests. Not sure if the failures were legitimate or not.

@justinmc justinmc added the CICD Run CI/CD label Aug 24, 2026
The centerSlice path in `paintImage` used a strict `==` comparison
between `sourceSize` and `inputSize`. When the image's pixel dimensions
are not evenly divisible by `scale`, the `inputSize / scale * scale`
round trip lands a few ULPs away from the original `inputSize`, and the
assertion fires for what is otherwise a valid configuration.

The same code path also fires when the destination rect is too small to
fit the centerSlice borders: `outputSize` becomes non-positive,
`applyBoxFit` degenerates to `Size.zero`, and the assertion compares
against zero for an unrelated reason.

This change tolerates double-precision rounding via
`precisionErrorTolerance` and skips the assertion entirely when the
slice borders cannot fit, which preserves the original safety check for
real BoxFit-induced source dropping while no longer breaking on either
edge case.

Refs flutter#27827
@Renzo-Olivares
Renzo-Olivares force-pushed the paint-image-center-slice-precision branch from a6426e9 to 0d1fb1b Compare August 25, 2026 23:01
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 25, 2026
@Renzo-Olivares Renzo-Olivares added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Aug 25, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Aug 26, 2026
Merged via the queue into flutter:master with commit e6aa89e Aug 26, 2026
30 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 26, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Aug 28, 2026
Roll Flutter from 15d8908addf6 to e8dca90ec9e0 (58 revisions)

flutter/flutter@15d8908...e8dca90

2026-08-27 [email protected] Terminate existing process before launching with devicectl (flutter/flutter#191885)
2026-08-27 [email protected] Roll Fuchsia Linux SDK from qjOQi-zAgu_tADorh... to dDxH8G5cDBP602eyG... (flutter/flutter#191889)
2026-08-27 [email protected] [flutter_tools] Verify native assets tree-shaking during linking (flutter/flutter#191637)
2026-08-27 [email protected] Denylists b-series powervr from vulkan (flutter/flutter#191808)
2026-08-27 [email protected] Handle linear and radial gradients in UberSDF (flutter/flutter#190874)
2026-08-27 [email protected] Roll Packages from 740f093 to bd3cbc1 (7 revisions) (flutter/flutter#191886)
2026-08-27 [email protected] Disable more Windows tests that have been causing CI flakes (flutter/flutter#191822)
2026-08-27 [email protected] Roll Skia from d32721369bd8 to 82e972ea84b1 (2 revisions) (flutter/flutter#191880)
2026-08-27 [email protected] Roll Skia from 3640b8edd16c to d32721369bd8 (10 revisions) (flutter/flutter#191858)
2026-08-27 [email protected] Revert: [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191863)
2026-08-27 [email protected] Roll Fuchsia Test Scripts from 0iCv10IlKfiilEBOU... to 6SXRz6wsA2Zm_rAqP... (flutter/flutter#191852)
2026-08-27 [email protected] Roll pub packages (flutter/flutter#191851)
2026-08-27 [email protected] Refactor FormField build wrappers (flutter/flutter#185795)
2026-08-27 [email protected] Make ScrollPhysics reactive by introducing shouldUpdate (flutter/flutter#189664)
2026-08-27 [email protected] macOS: Fix crash on out-of-bounds text input ranges (flutter/flutter#191780)
2026-08-27 [email protected] Add HCPP feature flag, and turn it on by default in beta/master (flutter/flutter#190623)
2026-08-27 [email protected] [tool] Migrate CleanCommand to modular dependency injection (flutter/flutter#190742)
2026-08-26 [email protected] Update triage docs for ecosystem and codelab changes (flutter/flutter#191809)
2026-08-26 [email protected] [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191824)
2026-08-26 [email protected] [UIScene] Migrate dev/benchmarks/complex_layout to UIScene lifecycle (flutter/flutter#191619)
2026-08-26 [email protected] Add SliverAppBar showOnScreen semantics test coverage (flutter/flutter#190410)
2026-08-26 [email protected] Add prompt_suggestion icon to list of RTL mirroring icons. (flutter/flutter#191741)
2026-08-26 [email protected] Remove bringup for batch 3 (flutter/flutter#191750)
2026-08-26 [email protected] Roll Skia from b5465d7b0b77 to 3640b8edd16c (6 revisions) (flutter/flutter#191835)
2026-08-26 [email protected] Uiscene migrate custom channels views (flutter/flutter#191817)
2026-08-26 [email protected] Support --[no-]adb-log-filtering CLI option (flutter/flutter#187252)
2026-08-26 [email protected] Roll Dart SDK from cb8a4e1a0fbb to cb4c39d067f3 (2 revisions) (flutter/flutter#191825)
2026-08-26 [email protected] Fix `Navigator.pushNamed<T>()` type checking (flutter/flutter#188148)
2026-08-26 [email protected] Handle the case where a window doesn't have a title set (flutter/flutter#191767)
2026-08-26 [email protected] [Android] Remove old `InputType` constructor from embedding (flutter/flutter#191244)
2026-08-26 [email protected] Roll Skia from 244a6a0f8f92 to b5465d7b0b77 (19 revisions) (flutter/flutter#191810)
2026-08-26 [email protected] Tolerate floating-point rounding in paintImage centerSlice assertion (flutter/flutter#185789)
2026-08-26 [email protected] Fixes translated bounded blurs (flutter/flutter#191615)
2026-08-26 [email protected] Roll Fuchsia Linux SDK from MstTWE1RDOT-RnrtH... to qjOQi-zAgu_tADorh... (flutter/flutter#191769)
2026-08-26 [email protected] Lerp HSVColor and HSLColor hue along the shortest arc (flutter/flutter#191186)
2026-08-26 [email protected] Fix enum instances comparison to use `equality ==` since dart has the correct behavior now (flutter/flutter#191537)
2026-08-26 [email protected] Switches windows to opengles 3 (flutter/flutter#191516)
2026-08-26 [email protected] Roll Dart SDK from 7739e8602bc1 to cb8a4e1a0fbb (1 revision) (flutter/flutter#191784)
2026-08-26 [email protected] iOS,macOS: Check viewType before creating a platform view (flutter/flutter#191777)
2026-08-26 [email protected] Revert: [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191793)
2026-08-26 [email protected] refactor(flutter_tools): clean up dead unreferenced declarations (flutter/flutter#191163)
2026-08-26 [email protected] Roll Fuchsia GN SDK from a87CbQSWEjkPUK1ZY... to ZsxUUK2SfA-TrNvb8... (flutter/flutter#191763)
2026-08-26 [email protected] [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191732)
2026-08-25 [email protected] Remove legacy gen_defaults analyze checks (flutter/flutter#191629)
2026-08-25 [email protected] Refactors `try` to avoid `unawaited_return_in_try_block` case (flutter/flutter#191129)
2026-08-25 [email protected] Roll Dart SDK from 8996935d3d0a to 7739e8602bc1 (1 revision) (flutter/flutter#191754)
...
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12660)

Roll Flutter from 15d8908addf6 to e8dca90ec9e0 (58 revisions)

flutter/flutter@15d8908...e8dca90

2026-08-27 [email protected] Terminate existing process before launching with devicectl (flutter/flutter#191885)
2026-08-27 [email protected] Roll Fuchsia Linux SDK from qjOQi-zAgu_tADorh... to dDxH8G5cDBP602eyG... (flutter/flutter#191889)
2026-08-27 [email protected] [flutter_tools] Verify native assets tree-shaking during linking (flutter/flutter#191637)
2026-08-27 [email protected] Denylists b-series powervr from vulkan (flutter/flutter#191808)
2026-08-27 [email protected] Handle linear and radial gradients in UberSDF (flutter/flutter#190874)
2026-08-27 [email protected] Roll Packages from 740f093 to bd3cbc1 (7 revisions) (flutter/flutter#191886)
2026-08-27 [email protected] Disable more Windows tests that have been causing CI flakes (flutter/flutter#191822)
2026-08-27 [email protected] Roll Skia from d32721369bd8 to 82e972ea84b1 (2 revisions) (flutter/flutter#191880)
2026-08-27 [email protected] Roll Skia from 3640b8edd16c to d32721369bd8 (10 revisions) (flutter/flutter#191858)
2026-08-27 [email protected] Revert: [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191863)
2026-08-27 [email protected] Roll Fuchsia Test Scripts from 0iCv10IlKfiilEBOU... to 6SXRz6wsA2Zm_rAqP... (flutter/flutter#191852)
2026-08-27 [email protected] Roll pub packages (flutter/flutter#191851)
2026-08-27 [email protected] Refactor FormField build wrappers (flutter/flutter#185795)
2026-08-27 [email protected] Make ScrollPhysics reactive by introducing shouldUpdate (flutter/flutter#189664)
2026-08-27 [email protected] macOS: Fix crash on out-of-bounds text input ranges (flutter/flutter#191780)
2026-08-27 [email protected] Add HCPP feature flag, and turn it on by default in beta/master (flutter/flutter#190623)
2026-08-27 [email protected] [tool] Migrate CleanCommand to modular dependency injection (flutter/flutter#190742)
2026-08-26 [email protected] Update triage docs for ecosystem and codelab changes (flutter/flutter#191809)
2026-08-26 [email protected] [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191824)
2026-08-26 [email protected] [UIScene] Migrate dev/benchmarks/complex_layout to UIScene lifecycle (flutter/flutter#191619)
2026-08-26 [email protected] Add SliverAppBar showOnScreen semantics test coverage (flutter/flutter#190410)
2026-08-26 [email protected] Add prompt_suggestion icon to list of RTL mirroring icons. (flutter/flutter#191741)
2026-08-26 [email protected] Remove bringup for batch 3 (flutter/flutter#191750)
2026-08-26 [email protected] Roll Skia from b5465d7b0b77 to 3640b8edd16c (6 revisions) (flutter/flutter#191835)
2026-08-26 [email protected] Uiscene migrate custom channels views (flutter/flutter#191817)
2026-08-26 [email protected] Support --[no-]adb-log-filtering CLI option (flutter/flutter#187252)
2026-08-26 [email protected] Roll Dart SDK from cb8a4e1a0fbb to cb4c39d067f3 (2 revisions) (flutter/flutter#191825)
2026-08-26 [email protected] Fix `Navigator.pushNamed<T>()` type checking (flutter/flutter#188148)
2026-08-26 [email protected] Handle the case where a window doesn't have a title set (flutter/flutter#191767)
2026-08-26 [email protected] [Android] Remove old `InputType` constructor from embedding (flutter/flutter#191244)
2026-08-26 [email protected] Roll Skia from 244a6a0f8f92 to b5465d7b0b77 (19 revisions) (flutter/flutter#191810)
2026-08-26 [email protected] Tolerate floating-point rounding in paintImage centerSlice assertion (flutter/flutter#185789)
2026-08-26 [email protected] Fixes translated bounded blurs (flutter/flutter#191615)
2026-08-26 [email protected] Roll Fuchsia Linux SDK from MstTWE1RDOT-RnrtH... to qjOQi-zAgu_tADorh... (flutter/flutter#191769)
2026-08-26 [email protected] Lerp HSVColor and HSLColor hue along the shortest arc (flutter/flutter#191186)
2026-08-26 [email protected] Fix enum instances comparison to use `equality ==` since dart has the correct behavior now (flutter/flutter#191537)
2026-08-26 [email protected] Switches windows to opengles 3 (flutter/flutter#191516)
2026-08-26 [email protected] Roll Dart SDK from 7739e8602bc1 to cb8a4e1a0fbb (1 revision) (flutter/flutter#191784)
2026-08-26 [email protected] iOS,macOS: Check viewType before creating a platform view (flutter/flutter#191777)
2026-08-26 [email protected] Revert: [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191793)
2026-08-26 [email protected] refactor(flutter_tools): clean up dead unreferenced declarations (flutter/flutter#191163)
2026-08-26 [email protected] Roll Fuchsia GN SDK from a87CbQSWEjkPUK1ZY... to ZsxUUK2SfA-TrNvb8... (flutter/flutter#191763)
2026-08-26 [email protected] [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191732)
2026-08-25 [email protected] Remove legacy gen_defaults analyze checks (flutter/flutter#191629)
2026-08-25 [email protected] Refactors `try` to avoid `unawaited_return_in_try_block` case (flutter/flutter#191129)
2026-08-25 [email protected] Roll Dart SDK from 8996935d3d0a to 7739e8602bc1 (1 revision) (flutter/flutter#191754)
...
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
…r#12660)

Roll Flutter from 15d8908addf6 to e8dca90ec9e0 (58 revisions)

flutter/flutter@15d8908...e8dca90

2026-08-27 [email protected] Terminate existing process before launching with devicectl (flutter/flutter#191885)
2026-08-27 [email protected] Roll Fuchsia Linux SDK from qjOQi-zAgu_tADorh... to dDxH8G5cDBP602eyG... (flutter/flutter#191889)
2026-08-27 [email protected] [flutter_tools] Verify native assets tree-shaking during linking (flutter/flutter#191637)
2026-08-27 [email protected] Denylists b-series powervr from vulkan (flutter/flutter#191808)
2026-08-27 [email protected] Handle linear and radial gradients in UberSDF (flutter/flutter#190874)
2026-08-27 [email protected] Roll Packages from 740f093 to bd3cbc1 (7 revisions) (flutter/flutter#191886)
2026-08-27 [email protected] Disable more Windows tests that have been causing CI flakes (flutter/flutter#191822)
2026-08-27 [email protected] Roll Skia from d32721369bd8 to 82e972ea84b1 (2 revisions) (flutter/flutter#191880)
2026-08-27 [email protected] Roll Skia from 3640b8edd16c to d32721369bd8 (10 revisions) (flutter/flutter#191858)
2026-08-27 [email protected] Revert: [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191863)
2026-08-27 [email protected] Roll Fuchsia Test Scripts from 0iCv10IlKfiilEBOU... to 6SXRz6wsA2Zm_rAqP... (flutter/flutter#191852)
2026-08-27 [email protected] Roll pub packages (flutter/flutter#191851)
2026-08-27 [email protected] Refactor FormField build wrappers (flutter/flutter#185795)
2026-08-27 [email protected] Make ScrollPhysics reactive by introducing shouldUpdate (flutter/flutter#189664)
2026-08-27 [email protected] macOS: Fix crash on out-of-bounds text input ranges (flutter/flutter#191780)
2026-08-27 [email protected] Add HCPP feature flag, and turn it on by default in beta/master (flutter/flutter#190623)
2026-08-27 [email protected] [tool] Migrate CleanCommand to modular dependency injection (flutter/flutter#190742)
2026-08-26 [email protected] Update triage docs for ecosystem and codelab changes (flutter/flutter#191809)
2026-08-26 [email protected] [AGP 9] Update remaining tests to AGP 9 (flutter/flutter#191824)
2026-08-26 [email protected] [UIScene] Migrate dev/benchmarks/complex_layout to UIScene lifecycle (flutter/flutter#191619)
2026-08-26 [email protected] Add SliverAppBar showOnScreen semantics test coverage (flutter/flutter#190410)
2026-08-26 [email protected] Add prompt_suggestion icon to list of RTL mirroring icons. (flutter/flutter#191741)
2026-08-26 [email protected] Remove bringup for batch 3 (flutter/flutter#191750)
2026-08-26 [email protected] Roll Skia from b5465d7b0b77 to 3640b8edd16c (6 revisions) (flutter/flutter#191835)
2026-08-26 [email protected] Uiscene migrate custom channels views (flutter/flutter#191817)
2026-08-26 [email protected] Support --[no-]adb-log-filtering CLI option (flutter/flutter#187252)
2026-08-26 [email protected] Roll Dart SDK from cb8a4e1a0fbb to cb4c39d067f3 (2 revisions) (flutter/flutter#191825)
2026-08-26 [email protected] Fix `Navigator.pushNamed<T>()` type checking (flutter/flutter#188148)
2026-08-26 [email protected] Handle the case where a window doesn't have a title set (flutter/flutter#191767)
2026-08-26 [email protected] [Android] Remove old `InputType` constructor from embedding (flutter/flutter#191244)
2026-08-26 [email protected] Roll Skia from 244a6a0f8f92 to b5465d7b0b77 (19 revisions) (flutter/flutter#191810)
2026-08-26 [email protected] Tolerate floating-point rounding in paintImage centerSlice assertion (flutter/flutter#185789)
2026-08-26 [email protected] Fixes translated bounded blurs (flutter/flutter#191615)
2026-08-26 [email protected] Roll Fuchsia Linux SDK from MstTWE1RDOT-RnrtH... to qjOQi-zAgu_tADorh... (flutter/flutter#191769)
2026-08-26 [email protected] Lerp HSVColor and HSLColor hue along the shortest arc (flutter/flutter#191186)
2026-08-26 [email protected] Fix enum instances comparison to use `equality ==` since dart has the correct behavior now (flutter/flutter#191537)
2026-08-26 [email protected] Switches windows to opengles 3 (flutter/flutter#191516)
2026-08-26 [email protected] Roll Dart SDK from 7739e8602bc1 to cb8a4e1a0fbb (1 revision) (flutter/flutter#191784)
2026-08-26 [email protected] iOS,macOS: Check viewType before creating a platform view (flutter/flutter#191777)
2026-08-26 [email protected] Revert: [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191793)
2026-08-26 [email protected] refactor(flutter_tools): clean up dead unreferenced declarations (flutter/flutter#191163)
2026-08-26 [email protected] Roll Fuchsia GN SDK from a87CbQSWEjkPUK1ZY... to ZsxUUK2SfA-TrNvb8... (flutter/flutter#191763)
2026-08-26 [email protected] [tool_tests] Remove bringup from Windows tool_tests_commands_2_2 (flutter/flutter#191732)
2026-08-25 [email protected] Remove legacy gen_defaults analyze checks (flutter/flutter#191629)
2026-08-25 [email protected] Refactors `try` to avoid `unawaited_return_in_try_block` case (flutter/flutter#191129)
2026-08-25 [email protected] Roll Dart SDK from 8996935d3d0a to 7739e8602bc1 (1 revision) (flutter/flutter#191754)
...
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.

centerSlice throws exception when scaling down

4 participants