LWJGL Forum

Programming => Bug Reports / RFE => Topic started by: orange451 on February 10, 2018, 04:35:07

Title: nnvgText and nvgText lead to a JVM crash after running for awhile
Post by: orange451 on February 10, 2018, 04:35:07
Not quite sure what is going on. This crash does not happen on MacOS, but always happens on my windows machine. If I call either nnvgText or nvgText over an extended period of time, the JVM will crash.

Here's the crash log:
https://pastebin.com/DrX29TUf

If there's any more info you need let me know. If you'd like to see the project I've created let me know as well, if it'll help.

Here's my drawing code:
Code: [Select]
@Override
public void render(Context context) {
long vg = context.getNVG();
float absX = (int)getAbsoluteX();
float absY = (int)getAbsoluteY();

    ByteBuffer textBuffer = null;
    try {
        textBuffer = MemoryUtil.memUTF8(text, false);
        long start = MemoryUtil.memAddress(textBuffer);
        long end = start + textBuffer.remaining();

// Draw
NanoVG.nvgFontSize(vg, fontSize);
NanoVG.nvgFontFace(vg, Font.SANS.getFont(fontStyle));
NanoVG.nvgTextAlign(vg,NanoVG.NVG_ALIGN_LEFT|NanoVG.NVG_ALIGN_TOP);

NanoVG.nvgBeginPath(vg);
NanoVG.nvgFontBlur(vg,0);
NanoVG.nvgFillColor(vg, textColor.getNVG());
NanoVG.nnvgText(vg, absX, absY, start, end);
    } finally {
        if (textBuffer != null) {
            MemoryUtil.memFree(textBuffer);
        }
    }
}
Title: Re: nnvgText and nvgText lead to a JVM crash after running for awhile
Post by: spasi on February 10, 2018, 10:21:36
The most likely reason: you called nvgCreateFontMem using a .ttf buffer and now the buffer has been GCed. See the javadoc:

Quote
The memory chunk must remain valid for as long as the font is used by NanoVG.
Title: Re: nnvgText and nvgText lead to a JVM crash after running for awhile
Post by: orange451 on February 10, 2018, 23:45:25
I'll see if preventing the buffer from getting GC'd will help.

Putting it in an arraylist until shutdown /seems/ to be working. Will write back if it's still not working :)

Thanks.