Skip to content
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

Attempt to invoke virtual method 'int java.nio.ByteBuffer.capacity()' on a null object reference #223

Open
15balloon opened this issue Aug 28, 2024 · 1 comment

Comments

@15balloon
Copy link

15balloon commented Aug 28, 2024

New Issue Checklist

  • [ v ] I have searched for a similar issue in the project and found none

Issue Info

Info Value
Device Info
System Version
APNG4Android Library Version 3.0.1
Repro rate sometimes
Repro with our demo project
Demo project link

Issue Description and Steps

Glide Library Version: 4.16.0
APNG4Android Library Version: 3.0.1

Error Log:

com.github.penfeizhou.animation.decode.FrameSeqDecoder.getMemorySize(FrameSeqDecoder.java:578)
com.github.penfeizhou.animation.FrameAnimationDrawable.getMemorySize(FrameAnimationDrawable.java:301)
com.github.penfeizhou.animation.glide.FrameDrawableTranscoder$1.getSize(FrameDrawableTranscoder.java:48)
com.bumptech.glide.load.engine.EngineResource.getSize(EngineResource.java:62)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:40)
com.bumptech.glide.load.engine.cache.LruResourceCache.getSize(LruResourceCache.java:11)
com.bumptech.glide.util.LruCache.put(LruCache.java:131)
com.bumptech.glide.load.engine.cache.LruResourceCache.put(LruResourceCache.java:11)
com.bumptech.glide.load.engine.Engine.onResourceReleased(Engine.java:401)
com.bumptech.glide.load.engine.EngineResource.release(EngineResource.java:116)
com.bumptech.glide.load.engine.Engine.release(Engine.java:367)
com.bumptech.glide.request.SingleRequest.clear(SingleRequest.java:345)
com.bumptech.glide.manager.RequestTracker.clearAndRemove(RequestTracker.java:70)
com.bumptech.glide.RequestManager.untrack(RequestManager.java:677)
com.bumptech.glide.RequestManager.untrackOrDelegate(RequestManager.java:645)
com.bumptech.glide.RequestManager.clear(RequestManager.java:641)
com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:856)
com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:917)

exception:Attempt to invoke virtual method 'int java.nio.ByteBuffer.capacity()' on a null object reference

I just write code Glide.with(context).load(imageUrl).into(imageView).

In FrameSeqDecoder.java,

public int getMemorySize() {
    synchronized (cacheBitmapsLock) {
        int size = 0;
        for (Bitmap bitmap : cacheBitmaps) {
            if (bitmap.isRecycled()) {
                continue;
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                size += bitmap.getAllocationByteCount();
            } else {
                size += bitmap.getByteCount();
            }
        }
        if (frameBuffer != null) {
            size += frameBuffer.capacity();
        }
        return size;
    }
}

call capacity() after check frameBuffer is null.

But my project occurs error at there...
Sooo weird...

So I think... the frameBuffer check null in synchronized block, but it reassigned to null outside of the synchronized block/method and then it call capacity(), which causes a null error.

I think you need to fix the frameBuffer to reassigned it within a synchronized block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@15balloon and others