crow-misia / libyuv-android

LibYUV for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BufferUnderflowException (Migration from 0.16.0 to 0.18.0)

aitambs opened this issue · comments

Hello,

I am having problems while migrating to latest version.
The following code used to work on 0.16.0:

private byte[] getNV21(Bitmap scaled) {
        argbBuffer.asBuffer().rewind();
        nv21Buffer.asBuffer().rewind();
        scaled.copyPixelsToBuffer(argbBuffer.asBuffer());
        ConvertKt.convert(argbBuffer,nv21Buffer);
        return nv21Buffer.asByteArray();
    }

But I get an exception in the new Code on 0.18.0:

private byte[] getNV21(Bitmap scaled) {
        argbBuffer.asBuffer().rewind();
        nv21Buffer.asBuffer().rewind();
        scaled.copyPixelsToBuffer(argbBuffer.asBuffer());
        argbBuffer.convertTo(nv21Buffer);
        return nv21Buffer.asByteArray();
    }

(Exception is in the "asByteArray()" method)

P.S
I used to allocated buffers using:

argbBuffer = ArgbBuffer.allocate(width,height);
nv21Buffer = Nv21Buffer.allocate(width,height);

And now:

argbBuffer = ArgbBuffer.Factory.allocate(width,height);
nv21Buffer = Nv21Buffer.Factory.allocate(width,height);

@aitambs
v0.19.1 is released.

Source buffer position was not being reset, causing a crash if a buffer operation had already been performed.

Thank you very much for the very quick fix! :-)