Giter VIP home page Giter VIP logo

Comments (6)

ianjoneill avatar ianjoneill commented on May 28, 2024

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.

jaredsburrows avatar jaredsburrows commented on May 28, 2024

@ianjoneill How did you get around this?
@felipecsl Any update on this?

from gifimageview.

ianjoneill avatar ianjoneill commented on May 28, 2024

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.

jaredsburrows avatar jaredsburrows commented on May 28, 2024

@ianjoneill Yes but after applying your fix, have you received this exception again?

from gifimageview.

ianjoneill avatar ianjoneill commented on May 28, 2024

Unfortunately I never got around to trying it out.

from gifimageview.

mattinger avatar mattinger commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.