bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.67k stars 6.12k forks source link

Compose GlideImage, high aspect ratio image load will crash. #5412

Open cuichanghao opened 5 months ago

cuichanghao commented 5 months ago

It seems only happen in high aspect ratio image will crash. Like 760x58, but normal image will not crash, like 760x500.

java.lang.RuntimeException: Canvas: trying to draw too large(105836080bytes) bitmap.
    at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
    at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
    at androidx.compose.ui.graphics.AndroidCanvas.drawImageRect-HPBpro0(AndroidCanvas.android.kt:275)
    at androidx.compose.ui.graphics.drawscope.CanvasDrawScope.drawImage-AZ2fEMs(CanvasDrawScope.kt:256)
    at androidx.compose.ui.node.LayoutNodeDrawScope.drawImage-AZ2fEMs(LayoutNodeDrawScope.kt:0)
    at androidx.compose.ui.graphics.drawscope.DrawScope.drawImage-AZ2fEMs$default(DrawScope.kt:551)
    at androidx.compose.ui.graphics.painter.BitmapPainter.onDraw(BitmapPainter.kt:93)
    at androidx.compose.ui.graphics.painter.Painter.draw-x_KDEd0(Painter.kt:212)
    at com.bumptech.glide.integration.compose.DoNotTransition$drawCurrent$1.invoke-QfoU1oo(Transition.kt:92)
    at com.bumptech.glide.integration.compose.DoNotTransition$drawCurrent$1.invoke(Transition.kt:90)
    at com.bumptech.glide.integration.compose.GlideNode$draw$2$1$1.invoke-d16Qtg0(GlideModifier.kt:346)
    at com.bumptech.glide.integration.compose.GlideNode$draw$2$1$1.invoke(GlideModifier.kt:345)
    at com.bumptech.glide.integration.compose.GlideNode.drawOne(GlideModifier.kt:326)
    at com.bumptech.glide.integration.compose.GlideNode.draw(GlideModifier.kt:345)
    at androidx.compose.ui.node.LayoutNodeDrawScope.drawDirect-x_KDEd0$ui_release(LayoutNodeDrawScope.kt:105)
    at androidx.compose.ui.node.LayoutNodeDrawScope.draw-x_KDEd0$ui_release(LayoutNodeDrawScope.kt:86)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:364)
    at androidx.compose.ui.node.NodeCoordinator.draw(NodeCoordinator.kt:353)
    at androidx.compose.ui.node.LayoutModifierNodeCoordinator.performDraw(LayoutModifierNodeCoordinator.kt:176)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:361)
    at androidx.compose.ui.node.NodeCoordinator.draw(NodeCoordinator.kt:353)
    at androidx.compose.ui.node.LayoutModifierNodeCoordinator.performDraw(LayoutModifierNodeCoordinator.kt:176)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:361)
    at androidx.compose.ui.node.NodeCoordinator.draw(NodeCoordinator.kt:353)
    at androidx.compose.ui.node.LayoutModifierNodeCoordinator.performDraw(LayoutModifierNodeCoordinator.kt:176)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:361)
    at androidx.compose.ui.node.NodeCoordinator.access$getTmpLayerPositionalProperties$cp(NodeCoordinator.kt:54)
    at androidx.compose.ui.node.NodeCoordinator.access$drawContainedDrawModifiers(NodeCoordinator.kt:54)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1$1.invoke(NodeCoordinator.kt:383)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1$1.invoke(NodeCoordinator.kt:382)
    at androidx.compose.runtime.snapshots.Snapshot.enter(Snapshot.kt:131)
    at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:476)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:500)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:256)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1.invoke(NodeCoordinator.kt:382)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1.invoke(NodeCoordinator.kt:380)
    at androidx.compose.ui.platform.RenderNodeApi29.record(RenderNodeApi29.android.kt:209)
    at androidx.compose.ui.platform.RenderNodeLayer.updateDisplayList(RenderNodeLayer.android.kt:335)
    at androidx.compose.ui.platform.RenderNodeLayer.drawLayer(RenderNodeLayer.android.kt:277)
    at androidx.compose.ui.node.NodeCoordinator.draw(NodeCoordinator.kt:348)
    at androidx.compose.ui.node.LayoutNode.draw$ui_release(LayoutNode.kt:926)
    at androidx.compose.ui.node.InnerNodeCoordinator.performDraw(InnerNodeCoordinator.kt:174)
    at androidx.compose.ui.node.LayoutNodeDrawScope.drawContent(LayoutNodeDrawScope.kt:66)
    at androidx.compose.foundation.DrawOverscrollModifier.draw(AndroidOverscroll.android.kt:81)
    at androidx.compose.ui.node.BackwardsCompatNode.draw(BackwardsCompatNode.kt:349)
    at androidx.compose.ui.node.LayoutNodeDrawScope.drawDirect-x_KDEd0$ui_release(LayoutNodeDrawScope.kt:105)
    at androidx.compose.ui.node.LayoutNodeDrawScope.draw-x_KDEd0$ui_release(LayoutNodeDrawScope.kt:86)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:364)
    at androidx.compose.ui.node.NodeCoordinator.draw(NodeCoordinator.kt:353)
    at androidx.compose.ui.node.LayoutModifierNodeCoordinator.performDraw(LayoutModifierNodeCoordinator.kt:176)
    at androidx.compose.ui.node.NodeCoordinator.drawContainedDrawModifiers(NodeCoordinator.kt:361)
    at androidx.compose.ui.node.NodeCoordinator.access$getTmpLayerPositionalProperties$cp(NodeCoordinator.kt:54)
    at androidx.compose.ui.node.NodeCoordinator.access$drawContainedDrawModifiers(NodeCoordinator.kt:54)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1$1.invoke(NodeCoordinator.kt:383)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1$1.invoke(NodeCoordinator.kt:382)
    at androidx.compose.runtime.snapshots.Snapshot.enter(Snapshot.kt:131)
    at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:476)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:500)
    at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:256)
    at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1.invoke(NodeCoordinator.kt:382)
    at androidx.compose.ui.node.NodeCoordinator$drawBlock$1.invoke(NodeCoordinator.kt:380)
    at androidx.compose.ui.platform.RenderNodeApi29.record(RenderNodeApi29.android.kt:209)
    at androidx.compose.ui.platform.RenderNodeLayer.updateDisplayList(RenderNodeLayer.android.kt:335)
    at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:1236)
    at android.view.View.draw(View.java:23202)
    at android.view.View.updateDisplayListIfDirty(View.java:22066)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4533)
    at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4506)
    at android.view.View.updateDisplayListIfDirty(View.java:22022)
    at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:682)
    at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:688)
    at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:786)
    at android.view.ViewRootImpl.draw(ViewRootImpl.java:4582)
    at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4293)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3520)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2289)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8958)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1319)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1327)
    at android.view.Choreographer.doCallbacks(Choreographer.java:985)
    at android.view.Choreographer.doFrame(Choreographer.java:916)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1302)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7972)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)

Call site

    // This will crash high ratio image.
    GlideImage(
        model = remember,
        contentDescription = contentDescription,
        contentScale = contentScale,
        modifier = modifier
            .aspectRatio(width.toFloat() / height.toFloat(), matchHeightConstraintsFirst = true),
        requestBuilderTransform = requestListener,
    )

Normal image is no problem, or if i not specify aspectRatio for GlideImage is no problem.

    // This is work even high ratio image.
    GlideImage(
        model = remember,
        contentDescription = contentDescription,
        contentScale = contentScale,
        requestBuilderTransform = requestListener,
    )

May be related to https://github.com/bumptech/glide/issues/4485

We use glide_compose = "1.0.0-beta01"