Programming => General Java Game Development => Topic started by: sc on November 20, 2019, 10:22:19

Title: DirectByteBuffer crash / stbi_load_from_memory ?
Post by: sc on November 20, 2019, 10:22:19
My application crashes after about 30 seconds and I can't figure out why ...  :-[
I've used lwjgl_xdebug to track it down to this code :

Code: [Select]
public void load_img(String tx_path) throws RuntimeException {
ByteBuffer bf_img = null;

try {
bf_img = OGLFile.load_file_into_byteBf(tx_path); // System.out.println(bf_img.isDirect()); // T

// do stuff

} catch(IOException e) {
throw new RuntimeException("ERR loading tx from " + tx_path);
} finally {    // why is this causing a crash after about 30 sec ???
if(bf_img != null) MemoryUtil.memFree(bf_img); // CRASH : java.lang.IllegalStateException: The memory address specified is not being tracked


Code: [Select]
public static ByteBuffer load_file_into_byteBf(String path) throws IOException {
// stuff
bf = MemoryUtil.memAlloc(init_buffer_cap_in_bytes);
// stuff
return bf;

If I comment out the memFree() line all is well.

I'm currently using that bf_img with STBImage.stbi_load_from_memory(bf_img ...).

EDIT : I don't think my code crashes because I created bf_img as a local variable ... But since there's c++ doing stuff in the background, I just wanted to check with more knowledgable programmers.
So, if it's not -that-, then the stbi_load_from_memory() must not like it when the buffer it has read from (bf_img) gets deleted ???