From 2ca4748e00ca8cc432fd61ec6ef065ce2ec2753c Mon Sep 17 00:00:00 2001 From: Michelle Tang Date: Thu, 11 Dec 2025 17:34:18 -0500 Subject: [PATCH] Fix long press crash on long polls. --- .../conversation/ConversationItemSelection.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItemSelection.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItemSelection.kt index 5966bc5836..601860e6a1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItemSelection.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItemSelection.kt @@ -17,6 +17,8 @@ import org.thoughtcrime.securesms.util.hasNoBubble object ConversationItemSelection { + const val MAX_SIZE: Long = 4096 * 4096 + @JvmStatic fun snapshotView( target: InteractiveConversationElement, @@ -45,7 +47,7 @@ object ConversationItemSelection { ): Bitmap { val snapshotStrategy = target.getSnapshotStrategy() if (snapshotStrategy != null) { - return createBitmap(target.root.width, target.root.height).applyCanvas { + return createSafeBitmap(target.root.width, target.root.height).applyCanvas { snapshotStrategy.snapshot(this) } } @@ -94,7 +96,7 @@ object ConversationItemSelection { if (hasReaction) { bitmapHeight += (reactionsView.height - DimensionUnit.DP.toPixels(4f)).toInt() } - return createBitmap(bodyBubble.width, bitmapHeight).applyCanvas { + return createSafeBitmap(bodyBubble.width, bitmapHeight).applyCanvas { if (drawConversationItem) { bodyBubble.draw(this) } @@ -121,6 +123,16 @@ object ConversationItemSelection { bodyBubble.scaleY = originalScale } } + + private fun createSafeBitmap(width: Int, height: Int): Bitmap { + return if (width * height < MAX_SIZE) { + createBitmap(width, height) + } else { + // Since this is only called in rare cases where the height is incredibly large / 'Read more' has not been triggered yet, + // used a general solution instead of something more algorithmic. + createBitmap(width, height / 2) + } + } } private fun ViewGroup.destroyAllDrawingCaches() {