LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: nnvgText and nvgText lead to a JVM crash after running for awhile  (Read 75 times)

orange451

  • Newbie
  • *
  • Offline Offline
  • Posts: 33

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);
        }
    }
}
Logged

spasi

  • Administrator
  • Nerdus Imperius
  • *****
  • Offline Offline
  • Posts: 1939
Re: nnvgText and nvgText lead to a JVM crash after running for awhile
« Reply #1 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.
Logged

orange451

  • Newbie
  • *
  • Offline Offline
  • Posts: 33
Re: nnvgText and nvgText lead to a JVM crash after running for awhile
« Reply #2 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.
Logged