penfeizhou / APNG4Android

Android animation support for APNG & Animated WebP & Gif & Animated AVIF, High performance
Apache License 2.0
570 stars 75 forks source link

Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference on Activity Pause #127

Closed Ferdari closed 2 years ago

Ferdari commented 2 years ago

New Issue Checklist

Issue Info

Info Value
Device Info e.g. ZTE Blade V9, LG V50
System Version e.g. 7.1, 11
APNG4Android Library Version e.g. 2.16.1
Repro rate e.g. all the time (100%)
Repro with our demo project e.g. Yes
Demo project link e.g. link to a demo project that highlights the issue

Issue Description and Steps

Hi, i have loaded 10-20 animated webps, it displays perfect, but when click a button that opens another Activity or AD it crashes with error: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:65) at android.graphics.BaseCanvas.drawBitmap(BaseCanvas.java:113) at android.graphics.Canvas.drawBitmap(Canvas.java:1555) at com.github.penfeizhou.animation.webp.decode.AnimationFrame.draw(AnimationFrame.java:100) at com.github.penfeizhou.animation.webp.decode.AnimationFrame.draw(AnimationFrame.java:21) at com.github.penfeizhou.animation.webp.decode.WebPDecoder.renderFrame(WebPDecoder.java:147) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.step(FrameSeqDecoder.java:505) at com.github.penfeizhou.animation.decode.FrameSeqDecoder.access$200(FrameSeqDecoder.java:36) at com.github.penfeizhou.animation.decode.FrameSeqDecoder$1.run(FrameSeqDecoder.java:60) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.os.HandlerThread.run(HandlerThread.java:67) It happen with all kind of animated webp, i think when activity got paused. i tried LG V50 and ZTE V9

penfeizhou commented 2 years ago

Would you please provide a demo project or sample code show how you use it?

Ferdari commented 2 years ago

I rechecked my code it happens when i click a button that opens an Ad and set a wait for ActivityResume, when the app resumes it crashes with the error privded, i deleted the Wait for and it are solved, no error.

Sorry but im using Basic4Android and a wrapper( that i wrapped) of your lib,

Ferdari commented 2 years ago

Again me, i checked again and the problem still there, i debuged line by line, on Activity create the Webps are loaded to imageviews and displays perfect, then i click button, it access other modules for checking data before displaying another activity, when accessing the modules it throws error every time other modules are working, SAME ERROR, then CRASH Activity. can you check it,

it appears to be when the imageviews are playing and shown but goes to background or the activity pauses. i don't know how to call it.

penfeizhou commented 2 years ago

You can try version 2.17.0,I added some protection

Ferdari commented 2 years ago

You can try version 2.17.0,I added some protection

Thank you, i will try and reply back...

Ferdari commented 2 years ago

oh sorry for bothering again, can you publish the AAR to maven repository, my wrapper uses AAR file to work with, i downloaded you lib from here as AAR: https://mvnrepository.com/artifact/com.github.penfeizhou.android.animation/awebp

I dont know if hard to do, or can you tell me how. THANKS

penfeizhou commented 2 years ago

I did publish to maven center. The synchronization need some time. You can download here. https://s01.oss.sonatype.org/content/repositories/releases/com/github/penfeizhou/android/animation/

Ferdari commented 2 years ago

Its perfect! no errors thrown now, only one thing weird happened, its like the the imageviews lost frames when resumed, like white white white frame white white frame. but not a problem right now, i can redraw/reload the views on resume.

Thanks a lot @penfeizhou, keep up the great work!