Janrupf/ultralight-java-reborn

JNIUlBitmap.nativeUnlockPixels throws JNI Exception

Opened this issue · 4 comments

Hi,

I am trying to get a bitmap of the surface and copy that to some texture. Here's the code

        UltralightBitmapSurface surface = (UltralightBitmapSurface) view.surface();
        UltralightBitmap bitmap = surface.bitmap();
        UltralightBuffer lock = bitmap.lockPixels();
        texture.setPixels(bitmap.rawPixels()); // some other engine code
        lock.close();

However, the above code throws this JNI exception:
Caused by: java.lang.UnsatisfiedLinkError: 'void net.janrupf.ujr.platform.jni.impl.JNIUlBitmap.nativeUnlockPixels(byte[])'

This makes the error not occur.

NioUltralightBuffer lock = new NioUltralightBuffer(bitmap.lockPixels().asByteBuffer());

In the docs it says:

The pixels are unlocked when the buffer is closed.

So when I close the buffer:

lock.close();

It should unlock the pixels right? But it doesn't seem like it unlocks the pixels.

(I think I'm very wrong here so please correct me, I don't know what I'm doing.)

The problem is in the JNI code. Your code to wrap the buffer into a NioUltralightBuffer does not work. NioUltralightBuffer does not close.

Sorry. It seems like the error didn't occur because NioUltralightBuffer does nothing on close.

@Override
public void close() {
    /* no-op */
}

Does the error occur because there's no Java_net_janrupf_ujr_platform_jni_impl_JNIUlBitmap_nativeUnlockPixels in Bitmap.cpp?

So do I have to wait until the dev fixes this? Or is there a workaround?

Calling lockPixels on UltralightBitmapSurface instead of UltralightBitmap works for me.

UltralightBitmapSurface surface = (UltralightBitmapSurface) view.surface();
UltralightBuffer lock = surface.lockPixels();
// do stuff here
lock.close();