-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
isRecycled() on a null object reference #2609
Comments
Hey! 👋 The issue doesn't seem to contain a minimal reproduction. Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem? |
We're seeing this happen on our end too. No repro steps either unfortunately. Also can confirm that the overwhelming majority is on Android 10 (99.8% of occurrences). |
I see this crash in my application too What are you thinking about this though? |
Hey, thanks for bringing up that issue. It’s definitely concerning, but I’m unable to reproduce it or guess the root cause, especially since the stack trace is obscured (e.g., |
Hi @jakex7 , hope this helps:
|
Looking at the internal code for react-native-svg, I'm not sure how it becomes null. There is a null check at the top for void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
if (mOpacity != 1) {
if (mLayerBitmap == null) {
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas = new Canvas(mLayerBitmap);
} else {
mLayerBitmap.recycle();
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas.setBitmap(mLayerBitmap);
}
// Copy current matrix from original canvas
mLayerCanvas.save();
mLayerCanvas.setMatrix(canvas.getMatrix());
} else {
mLayerCanvas = canvas;
}
// ...
if (mOpacity != 1) {
// Restore copied canvas and temporary reset original canvas matrix to draw bitmap 1:1
mLayerCanvas.restore();
int saveCount = canvas.save();
canvas.setMatrix(null);
mLayerPaint.setAlpha((int) (mOpacity * 255));
// crash
canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint);
canvas.restoreToCount(saveCount);
}
} |
I also analysed this code, I can only guess that Bitmap.createBitmap returns null on some devices/OS, but it is only assumption |
@maximzhemerenko I didn't see your earlier comment, but that could explain it. Nice idea. I will try a patch that does a 2nd null check
|
We released app and don't see new crashes after this fix #2609 (comment) who can confirm that this fix works on their app too? |
It's been working for me too |
I encountered this issue in my React Native app and attempted to reproduce it on a similar device, but was unsuccessful. only on Android and was not observed on Android 11 or higher in my app Affected models React-native version react-native-svg
|
Description
I have some users that get this crash report. (Only happens on Android 10)
Steps to reproduce
I haven't been able to figure out how to recreate this, but I haven't seen anyone report a crash related to
Bitmap.isRecycled()
and thought you might have some insight where this could come from.Snack or a link to a repository
n/a
SVG version
15.10.1
React Native version
0.76.5
Platforms
Android
JavaScript runtime
Hermes
Workflow
Expo Dev Client
Architecture
Paper (Old Architecture)
Build type
Release app & production bundle
Device
Real device
Device model
MAR-LX1A, SM-A207M, CPH1877
Acknowledgements
Yes
The text was updated successfully, but these errors were encountered: