Search code examples
javamalloclwjgl

LWJGL 3 malloc returning null?


So I am using lwjgl 3 and am trying to render text using the stb library. I am using this example to create my own implementation. But when I set STBTTPackedchar.Buffer using malloc it returns null. If i change the size to 3 * 128 instead of 6 * 128 it works fine. Maybe this is a problem with my understanding of malloc? To my knowledge malloc allocates memory in the form of bytes and will return null if it couldn't allocate that space memory. If that is the case I don't understand why this would be returning null as I have more than enough memory in my computer.

Here is a minimal test case:

import org.lwjgl.stb.STBTTPackedchar;

public class Test {

    private static STBTTPackedchar.Buffer chardata;

    public static void main(String[] args) {
        chardata = STBTTPackedchar.malloc(6 * 128);

        if (chardata == null) {
            System.out.println("Null");
        } else {
            System.out.println("Not Null");
        }

        chardata.free();
    }

}

Solution

  • There is a bug in the LWJGL 3.1.3 release affecting sized malloc (not calloc) allocations of struct buffers. This has already been fixed in the latest 3.1.4 stable and latest nightly builds, which can be downloaded from https://www.lwjgl.org/customize or from oss.sonatype.org's Maven Snapshot repository as 3.1.4-SNAPSHOT. Also the LWJGL 3.1.4 release will be likely happen this evening/night (CET time).

    For more information, see: https://github.com/LWJGL/lwjgl3/commit/c7c94340d6a9796d38b2fb8292fe6d1dbff8ff04

    And also the (edited) release notes of the current 3.1.3 release: https://github.com/LWJGL/lwjgl3/blob/master/doc/notes/3.1.3.md#known-issues