Canvas: trying to use a recycled bitmap
Closed this issue · 1 comments
krokyze commented
Hi,
I'm extending Confetto class to make my custom animation. This is all what I have:
@Override
protected void drawInternal(Canvas canvas, Matrix matrix, Paint paint, float x, float y,
float rotation, float percentAnimated) {
float scaleX = ((rotation % 720) - 180) / 180.0f;
if (scaleX > 1f) {
scaleX = 1f - (scaleX - 1f);
}
float centerXDiff = (getWidth() * scaleX) / 2;
if (scaleX < 0f) {
matrix.preTranslate(x + Math.abs(centerXDiff), y);
} else {
matrix.preTranslate(x - Math.abs(centerXDiff), y);
}
matrix.preRotate(rotation, 0, bitmapCenterY);
matrix.preScale(scaleX, 1f);
canvas.drawBitmap(bitmap, matrix, paint);
}
I cannot reproduce by myself, but I have a bunch of users having a fatal exception when last line "canvas.drawBitmap" gets called. What could be the problem? I checked your source code and couldn't find a place where you call bitmap.recycle().
This is the stacktrace:
Fatal Exception: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@1bafec58
at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1225)
at android.view.GLES20Canvas.drawBitmap(GLES20Canvas.java:589)
at MyCustomConfetto.drawInternal(MyCustomConfetto.java:57)
at com.github.jinatonic.confetti.confetto.Confetto.getWidth(Confetto.java:342)
at com.github.jinatonic.confetti.confetto.Confetto.getWidth(Confetto.java:332)
at com.github.jinatonic.confetti.ConfettiView.onDraw(ConfettiView.java:132)
krokyze commented
Just found out Glide was recycling those bitmaps.