Skip to content

Commit 719d3d8

Browse files
authored
fix: nullPointerException in GroupView when drawing bitmap on Android 10 and older (#2694)
# Summary Open Issue: [isRecycled() on a null object reference](#2609) This PR addresses a sporadic crash that occurs specifically on Android 10 (API 29) and older when rendering SVGs. * Although the code already handles the mLayerBitmap being null in an earlier section, the bitmap can still become null on Android 10 and below due to memory pressure or race conditions, ultimately leading to a crash. * Differences in how Bitmap memory handled and Canvas drawing operations are handled in these versions, make them more susceptible to this issue.) [Reference: Android Bitmap Memory Management](https://developer.android.com/topic/performance/graphics/manage-memory#recycle) ## Test Plan Unfortunately, it is bit hard to recreate this behaviour and it is very sporadic. I have patched this change in my app, and it has produced positive results. both for me and for some other users as well. (#2609 (comment)) ### What's required for testing (prerequisites)? - ### What are the steps to reproduce (after prerequisites)? - ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ❌ | | MacOS | ❌ | | Android | ✅ | | Web | ❌ |
1 parent 417b34e commit 719d3d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

android/src/main/java/com/horcrux/svg/GroupView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
165165
int saveCount = canvas.save();
166166
canvas.setMatrix(null);
167167
mLayerPaint.setAlpha((int) (mOpacity * 255));
168-
canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint);
168+
if (mLayerBitmap != null) {
169+
canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint);
170+
}
169171
canvas.restoreToCount(saveCount);
170172
}
171173
this.setClientRect(groupRect);

0 commit comments

Comments
 (0)