Repository: flutter
Issue: centerSlice throws exception when scaling down
Labels: c: crash,framework,a: images,has reproducible steps,P2,found in release: 3.3,found in release: 3.5,team-framework,triaged-framework

This seems closely related to https://github.com/flutter/flutter/issues/20013, but I'm not sure whether it is the same issue.

I have two images that are being used as resolution-aware assets: the "main" asset is 68x46, and the 3.0x pixel ratio version is 208x142. If I use the asset in an `Image` widget with no `centerSlice` it works fine -- the 3.0x version is rendered at the same size as the lower-res main image as expected. I can set the `width` and `height` properties and they work as well.

Next, if I include *only* the main asset and give it a `centerSlice` and set the size of the `Image` to 100x46 everything still works okay, the `centerSlice` is applied properly, and everything looks good.

However, as soon as I add the 3.0x version, Flutter fails an assertion and throws an error about the `BoxFit` being wrong (even though it isn't) and says to create an issue here.

It seems the problem is something to do with the `centerSlice` processing not handling the scaling correctly. The only way I can make the error go away is to set the `height` and `width` of the `Image` to something that is equal to or greater than the actual size of the 3.0x image. Of course, that is not an actual solution because then the image renders at that larger size instead of what it should be.

## Logs

```
I/flutter (10662): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (10662): The following assertion was thrown during paint():
I/flutter (10662): centerSlice was used with a BoxFit that does not guarantee that the image is fully
visible.
I/flutter (10662): 'package:flutter/src/painting/decoration_image.dart': Failed assertion: line 406 pos 12: 'sourceSize
I/flutter (10662): == inputSize'
I/flutter (10662):
I/flutter (10662): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (10662): more information in this error message to help you determine and fix the underlying cause.
I/flutter (10662): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (10662):   https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (10662):
I/flutter (10662): When the exception was thrown, this was the stack:
I/flutter (10662): #2      paintImage (package:flutter/src/painting/decoration_image.dart:406:12)
I/flutter (10662): #3      RenderImage.paint (package:flutter/src/rendering/image.dart:357:5)
I/flutter (10662): #4      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #5      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #6      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #7      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #8      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #9      _RenderFlex&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2273:15)
I/flutter (10662): #10     RenderFlex.paint (package:flutter/src/rendering/flex.dart:931:7)
I/flutter (10662): #11     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #12     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #13     RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:70:15)
I/flutter (10662): #14     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #15     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #16     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #17     RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:1974:11)
I/flutter (10662): #18     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #19     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #20     RenderShiftedBox.paint (package:flutter/src/rendering/shifted_box.dart:70:15)
I/flutter (10662): #21     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #22     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #23     _RenderCustomMultiChildLayoutBox&RenderBox&ContainerRenderObjectMixin&RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2273:15)
I/flutter (10662): #24     RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:361:5)
I/flutter (10662): #25     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #26     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #28     _RenderInkFeatures.paint (package:flutter/src/material/material.dart:491:11)
I/flutter (10662): #29     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #30     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #31     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #32     RenderPhysicalModel.paint.<anonymous closure> (package:flutter/src/rendering/proxy_box.dart:1724:88)
I/flutter (10662): #33     ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:29:12)
I/flutter (10662): #34     ClipContext.clipRRectAndPaint (package:flutter/src/painting/clip.dart:49:5)I/flutter (10662): #35     RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:1724:17)
I/flutter (10662): #36     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #37     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #38     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #39     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #40     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:173:13)
I/flutter (10662): #41     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:122:15)
I/flutter (10662): #42     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2094:7)
I/flutter (10662): #43     PaintingContext._repaintCompositedChild (package:flutter/src/rendering/object.dart:128:11)
I/flutter (10662): #44     PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:96:5)
I/flutter (10662): #45     PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:855:29)I/flutter (10662): #46     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:283:19)
I/flutter (10662): #47     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:686:13)
I/flutter (10662): #48     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (10662): #49     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (10662): #50     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (10662): #51     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (10662): #52     _invoke (dart:ui/hooks.dart:159:13)
I/flutter (10662): #53     _drawFrame (dart:ui/hooks.dart:148:3)
I/flutter (10662): (elided 2 frames from class _AssertionError)
I/flutter (10662):
I/flutter (10662): The following RenderObject was being processed when the exception was fired:
I/flutter (10662):   RenderImage#77fd3 relayoutBoundary=up6
I/flutter (10662):   creator: RawImage ← Semantics ← Image ← GoogleSignInButton ← BlocBuilder<AccountEvent,
I/flutter (10662):   AccountState> ← Column ← Padding ← DecoratedBox ← Container ← MediaQuery ← Padding ← SafeArea ← ⋯
I/flutter (10662):   parentData: <none> (can use size)
I/flutter (10662):   constraints: BoxConstraints(0.0<=w<=395.4, 0.0<=h<=Infinity)
I/flutter (10662):   size: Size(69.3, 47.3)
I/flutter (10662):   image: [208×142]
I/flutter (10662):   scale: 3.0
I/flutter (10662):   alignment: center
I/flutter (10662):   centerSlice: Rect.fromLTRB(53.0, 7.0, 55.0, 9.0)
I/flutter (10662):   invertColors: false
I/flutter (10662):   filterQuality: low
I/flutter (10662): This RenderObject has no descendants.
I/flutter (10662): ════════════════════════════════════════════════════════════════════════════════════════════════════
```

```
No issues found! (ran in 21.0s)
```

```
[√] Flutter (Channel beta, v1.1.8, on Microsoft Windows [Version 10.0.17763.55], locale en-US)
    • Flutter version 1.1.8 at C:\Users\Caleb\flutter
    • Framework revision 985ccb6d14 (5 weeks ago), 2019-01-08 13:45:55 -0800
    • Engine revision 7112b72cc2
    • Dart version 2.1.1 (build 2.1.1-dev.0.1 ec86471ccc)

[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\Users\Caleb\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    X Android license status unknown.

[√] Android Studio (version 3.3)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[√] VS Code (version 1.31.0)
    • VS Code at C:\Users\Caleb\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.22.3

[√] Connected device (1 available)
    • Pixel 2 XL • 709KPNY0046767 • android-arm64 • Android 9 (API 28)

! Doctor found issues in 1 category.
```