Skip to content

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

@15balloon

Description

@15balloon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions