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

MultimediaActivity: Canvas: trying to draw too large(192000000bytes) bitmap #17378

Open
Tracked by #17370
david-allison opened this issue Nov 7, 2024 · 5 comments
Open
Tracked by #17370

Comments

@david-allison
Copy link
Member

david-allison commented Nov 7, 2024

https://ankidroid.org/acra/app/1/bug/254079/report/8394c29e-bae5-4c6a-9684-09600daff226

java.lang.RuntimeException: Canvas: trying to draw too large(192000000bytes) bitmap.
	at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
	at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
	at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
	at android.widget.ImageView.onDraw(ImageView.java:1449)
	at android.view.View.draw(View.java:23351)
	at android.view.View.updateDisplayListIfDirty(View.java:22210)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.draw(View.java:23356)
	at android.view.View.updateDisplayListIfDirty(View.java:22210)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1994)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1277)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at androidx.fragment.app.FragmentContainerView.drawChild(FragmentContainerView.kt:232)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at androidx.fragment.app.FragmentContainerView.dispatchDraw(FragmentContainerView.kt:222)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1994)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1277)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.updateDisplayListIfDirty(View.java:22199)
	at android.view.View.draw(View.java:23076)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4544)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
	at android.view.View.draw(View.java:23356)
	at com.android.internal.policy.DecorView.draw(DecorView.java:896)
	at android.view.View.updateDisplayListIfDirty(View.java:22210)
	at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:682)
	at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:690)
	at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:795)
	at android.view.ViewRootImpl.draw(ViewRootImpl.java:4924)
	at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4625)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3813)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2543)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9465)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1451)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1459)
	at android.view.Choreographer.doCallbacks(Choreographer.java:1089)
	at android.view.Choreographer.doFrame(Choreographer.java:1003)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1431)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:211)
	at android.os.Looper.loop(Looper.java:300)
	at android.app.ActivityThread.main(ActivityThread.java:8289)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
@david-allison david-allison changed the title https://ankidroid.org/acra/app/1/bug/254079/report/8394c29e-bae5-4c6a-9684-09600daff226 MultimediaActivity: Canvas: trying to draw too large(192000000bytes) bitmap Nov 7, 2024
@david-allison
Copy link
Member Author

@criticalAY FYI

@criticalAY criticalAY self-assigned this Nov 7, 2024
@david-allison david-allison added this to the 2.19.2 release milestone Nov 7, 2024
@criticalAY
Copy link
Contributor

ImageView related issue, the code is being migrated to webview we can wait for the next release after

is merged this should be fixed hopefully

@mikehardy
Copy link
Member

I posted a PR that actually fixes this, using WebView does not really fix it (noted same in that PR, with repro)

@mikehardy
Copy link
Member

mikehardy commented Jan 22, 2025

Hmmm, definitely something about image size is still going bad, from the reddit link @Danika-Dakika posted (but in the PR, not in this issue)

Edit.2: I just checked and if i make the picture smaller with another app (not the anki picture cutting tool) I can use it and anki doesn't crash. So it is the size of the picture and instead of asking me to cut it with the anki cutting tool or even telling me that it is to big, it crashes.

Indeed, it's still this same crash somehow, I found it on ACRA thanks to Danika getting the debug info with the ACRA UUID

I believe the difference is my PR handled the paperclip icon and preview, but the "select image from gallery -> share to ankidroid add image" pathway apparently is no good. Cut-n-paste may be busted too, unsure

https://ankidroid.org/acra/app/1/bug/261649/report/b7d1fc5b-8efc-471f-9163-71e7b3653522

java.lang.RuntimeException: Canvas: trying to draw too large(256576512bytes) bitmap.
	at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:267)
	at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:98)
	at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:561)
	at android.widget.ImageView.onDraw(ImageView.java:1446)
	at android.view.View.draw(View.java:25177)
	at android.view.View.updateDisplayListIfDirty(View.java:24036)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.draw(View.java:25180)
	at android.view.View.updateDisplayListIfDirty(View.java:24036)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(SourceFile:29)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(SourceFile:14)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at androidx.fragment.app.FragmentContainerView.drawChild(SourceFile:31)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at androidx.fragment.app.FragmentContainerView.dispatchDraw(SourceFile:36)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(SourceFile:29)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(SourceFile:14)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at android.view.View.updateDisplayListIfDirty(View.java:24022)
	at android.view.View.draw(View.java:24907)
	at android.view.ViewGroup.drawChild(ViewGroup.java:4780)
	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4538)
	at com.android.internal.policy.DecorView.dispatchDraw(DecorView.java:1179)
	at android.view.View.draw(View.java:25180)
	at com.android.internal.policy.DecorView.draw(DecorView.java:1161)
	at android.view.View.updateDisplayListIfDirty(View.java:24036)
	at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:768)
	at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:774)
	at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:872)
	at android.view.ViewRootImpl.draw(ViewRootImpl.java:6051)
	at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:5706)
	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4795)
	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3288)
	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:11344)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1689)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1698)
	at android.view.Choreographer.doCallbacks(Choreographer.java:1153)
	at android.view.Choreographer.doFrame(Choreographer.java:1079)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1646)
	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:230)
	at android.os.Looper.loop(Looper.java:319)
	at android.app.ActivityThread.main(ActivityThread.java:8919)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

@mikehardy mikehardy reopened this Jan 22, 2025
@mikehardy mikehardy added the 2.21 label Jan 22, 2025
@david-allison
Copy link
Member Author

david-allison commented Jan 22, 2025

Caught this on reddit and thought I'd clarify here. The problem is the uncompressed size as a bitmap [width * height * bit depth], not necessarily the size of the image itself, which may be below the AnkiWeb limit.

Example: A 100,000 * 100,000 red square could potentially be compressed to a few bytes, but still blow this up

Similar issue:

fun validateBackgroundImageFileSize(
target: AppearanceSettingsFragment,
selectedImage: Uri,
): FileSizeResult {
val filePathColumn = arrayOf(MediaStore.MediaColumns.SIZE, MediaStore.MediaColumns.WIDTH, MediaStore.MediaColumns.HEIGHT)
target.requireContext().contentResolver.query(selectedImage, filePathColumn, null, null, null).use { cursor ->
cursor!!.moveToFirst()
val fileSizeInMB = cursor.getLong(0) / (1024 * 1024)
if (fileSizeInMB >= 10) {
return FileSizeResult.FileTooLarge(currentMB = fileSizeInMB, maxMB = 10)
}
val width = cursor.getLong(1)
val height = cursor.getLong(2)
// Default MAX_IMAGE_SIZE on Android
if (width * height * BITMAP_BYTES_PER_PIXEL > MAX_BITMAP_SIZE) {
return FileSizeResult.UncompressedBitmapTooLarge(width = width, height = height)
}
return FileSizeResult.OK
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants