ultralight-java-reborn icon indicating copy to clipboard operation
ultralight-java-reborn copied to clipboard

JNIUlBitmap.nativeUnlockPixels throws JNI Exception

Open insraq opened this issue 2 years ago • 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[])'

insraq avatar Sep 13 '23 17:09 insraq

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.)

hvven avatar Sep 16 '23 11:09 hvven

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

insraq avatar Sep 16 '23 11:09 insraq

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?

hvven avatar Sep 18 '23 07:09 hvven

Calling lockPixels on UltralightBitmapSurface instead of UltralightBitmap works for me.

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

hvven avatar Sep 18 '23 09:09 hvven