nnvgText and nvgText lead to a JVM crash after running for awhile

Started by orange451, February 10, 2018, 04:35:07

Previous topic - Next topic


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:

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:
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.nvgFillColor(vg, textColor.getNVG());
		NanoVG.nnvgText(vg, absX, absY, start, end);
    } finally {
        if (textBuffer != null) {


The most likely reason: you called nvgCreateFontMem using a .ttf buffer and now the buffer has been GCed. See the javadoc:

QuoteThe memory chunk must remain valid for as long as the font is used by NanoVG.


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 :)