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

JNIUlBitmap.nativeUnlockPixels throws JNI Exception #2

Open
insraq opened this issue Sep 13, 2023 · 4 comments
Open

JNIUlBitmap.nativeUnlockPixels throws JNI Exception #2

insraq opened this issue Sep 13, 2023 · 4 comments

Comments

@insraq
Copy link

insraq commented Sep 13, 2023

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[])'

@hvven
Copy link

hvven commented Sep 16, 2023

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

@insraq
Copy link
Author

insraq commented Sep 16, 2023

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

@hvven
Copy link

hvven commented Sep 18, 2023

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
Copy link

hvven commented Sep 18, 2023

Calling lockPixels on UltralightBitmapSurface instead of UltralightBitmap works for me.

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

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