nvgImagePattern w/ nvgCreateImage throws Null Pointer Exception

Started by Illari, February 25, 2019, 08:09:24

Previous topic - Next topic

Illari

Hi,

I'm making this small project in part to familiarise myself with some tools that might come useful in later projects, so I don't have much experience in Java or the tools used for it. I'm using NetBeans 8.2 and Java 8 202 (SE and runtime).

nvgImagePattern throws Null Pointer Exception when given an image created by nvgCreateImageMem. Same seems to happen with nvgCreateImage. Saving the image using stbi_write_png doesn't seem to do anything, so the problem might be with loading the image with stbi_load_from_memory. Printing the width, height and comp values works correctly, but texID/[i/] returns 0 on each iteration.

Another thing that happened was that tinyfd_inputBox seems to print the correct number but doesn't recognise it when comparing strings.

if (!("9".equals(lnk) || "13".equals(lnk) || "17".equals(lnk) || "21".equals(lnk)))  //Always true
            System.exit(0);


ByteBuffer imageBuffer = ioResourceToByteBuffer("kotlinapplication1/image/valikot_"+img[i]+".png", 8 * 1024);
MemoryStack stack = stackPush();
IntBuffer w    = stack.mallocInt(1);
IntBuffer h    = stack.mallocInt(1);
IntBuffer comp = stack.mallocInt(1);
stbi_info_from_memory(imageBuffer, w, h, comp);
ByteBuffer image = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
            
texID[i] = nvgCreateImageMem(vg, 0, image);
            nvgImagePattern(vg, 0, 0, 320, 360, 0, texID[i], 1, paint[i]);

spasi

Quote from: Illari on February 25, 2019, 08:09:24nvgImagePattern throws Null Pointer Exception when given an image created by nvgCreateImageMem

nvgCreateImageMem is just a shortcut for stbi_load_from_memory + nvgCreateImageRGBA. So, you can either:

1. Pass imageBuffer directly to nvgCreateImageMem and drop the stbi code.
2. Keep the code, but use nvgCreateImageRGBA instead of nvgCreateImageMem.

Quote from: Illari on February 25, 2019, 08:09:24Another thing that happened was that tinyfd_inputBox seems to print the correct number but doesn't recognise it when comparing strings.

Hmm, it looks like that, on Windows, the string returned by tinyfd_inputBox includes an extra "\r\n" at the end. I have patched tinyfd's implementation, the next 3.2.2 snapshot will include the fix.

Illari

Thank you, it was very helpful.

The remaining problem I had was solved by initialising the NVGPaints with NVGPaint.create().

Apparently pointers work... that way.

There are still a few problems I have to solve.

Thanks!