Hi, I'm using LWJGL 3.0.0 SNAPSHOT build 79 on Ubuntu 15.10 and having an issue with STBImage.stbi_load_from_memory.
The error I get is
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007fb305d6edeb, pid=1506, tid=140406906939136
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b17) (build 1.8.0_25-b17)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [liblwjgl.so+0x44deb]
The stack trace is
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j org.lwjgl.stb.STBImage.nstbi_load_from_memory(JIJJJI)J+0
j org.lwjgl.stb.STBImage.stbi_load_from_memory(Ljava/nio/ByteBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;Ljava/nio/IntBuffer;I)Ljava/nio/ByteBuffer;+43
j zaffre.imageutil$load_image.invoke(Ljava/lang/Object;)Ljava/lang/Object;+81
where zaffre.imageutil$load_image blah blah is my code.
The buffer argument looks like this when I print it
#object[java.nio.HeapByteBuffer 0xa1c50d5 "java.nio.HeapByteBuffer[pos=0 lim=378 cap=378]"]
I'm loading a png from disk that's 378 bytes so I can't find fault in that.
The x, y, and c arguments are IntBuffers created with BufferUtils.createIntBuffer(1)
just like https://github.com/LWJGL/lwjgl3/blob/master/modules/core/src/test/java/org/lwjgl/demo/stb/Image.java#L46
I know Clojure is a bit obscure but my routine looks like this https://github.com/aaron-santos/zaffre/blob/9def369d14535a654d8f8c534fefcd65f5d7b003/src/zaffre/imageutil.clj#L28 I can convert the section into Java if needed.
LWJGL does not support heap ByteBuffers, you must load the file contents into a direct ByteBuffer. IOUtils has methods that help with that afaik.
Even more efficient would be to use a MappedByteBuffer (see FileChannel.map), which avoids a copy. Instead of disk -> memory -> stb_image, you get disk -> stb_image.
Thank you. For now allocating a direct ByteBuffer and bulk copying worked.
https://github.com/aaron-santos/zaffre/blob/b68a7eba43881ec833c07230fa9d18f2e1ca00f7/src/zaffre/imageutil.clj#L32