Comments (6)
I don't think it will fix the problem, but making the animating
and shouldClear
fields of the GifImageView
class volatile
should reduce the chances of NPE's happening, see the java tutorial on Atomic Access.
from gifimageview.
@ianjoneill How did you get around this?
@felipecsl Any update on this?
from gifimageview.
I never came up with a reliable test-case (I've only ever seen the crash once), but as I mentioned in my previous comment, I think marking the animating
and shouldClear
fields as volatile
should help.
from gifimageview.
@ianjoneill Yes but after applying your fix, have you received this exception again?
from gifimageview.
Unfortunately I never got around to trying it out.
from gifimageview.
I've gotten around this by cleaning up directly in the thread where the run method is executing. There's not a good reason that I can see for the cleanup to happen in the main UI thread. I was able to easily produce this issue, by using gifImageView in a ViewPager, and cycling rapidly forward and backward.
The problem is that since the cleanup happens in another thread, the initial condition:
if (!animating && !renderFrame) {
break;
}
does not actually trigger the break, but then the cleanup runs in another thread, and sets gifDecoder to null.
I also remove the "tmpBitmap" variable as well, and replaced it with an inline anonymous runnable,
as it removes another race condition:
Bitmap bitmap = gifDecoder.getNextFrame();
if (frameCallback != null) {
bitmap = frameCallback.onFrameAvailable(bitmap);
}
final Bitmap tmpBitmap = bitmap;
frameDecodeTime = (System.nanoTime() - before) / 1000000;
handler.post(new Runnable() {
@Override
public void run() {
if (tmpBitmap != null && !tmpBitmap.isRecycled()) {
setImageBitmap(tmpBitmap);
}
}
});
from gifimageview.
Related Issues (20)
- First frame is overlapped over last frame on tranparent animated GIF HOT 4
- ANR exception in Google Play console. HOT 1
- Transparent GIF shows black. HOT 1
- Gif play speed varies from device to device HOT 2
- Does this support Android 4.4.2? HOT 3
- How to Load Gif image from File System HOT 1
- Frame might still get updated after stopAnimation is called
- No resetAnimation() HOT 3
- play animation for only once and stop HOT 1
- How could i get all frames of a .gif and store as jpeg in a folder using your "GifDecoder".
- Add the function from GifDecoder to get total frame count to the library
- cann't stop HOT 2
- NullPointerException HOT 2
- NullPointerException HOT 2
- Crashes in recycler view
- CreateProcess error=2, The system cannot find the file specified HOT 1
- How to display gif image from external storage ? HOT 2
- Stop at specific frame HOT 1
- getting Build failed after migrated to AndroidX HOT 4
- Memory leak due to rapid toggle of animation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gifimageview.