[solved] Nifty: Adding text to label causes out of memory error

I’m new to JME/nifty and I’m in the process of relearning Java, so I’m probably missing something simple here. I’ve been borrowing bits and pieces from the JME and nifty tutorials. Right now I’m integrating with RedDwarf to try to get a basic chat system working.

The problem I’m having seems to be with adding text with spaces to a label. The problem goes away when I replace all spaces in the strings with dashes.

Feb 13, 2011 7:13:25 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2760)
at java.util.Arrays.copyOf(Arrays.java:2734)
at java.util.ArrayList.ensureCapacity(ArrayList.java:167)
at java.util.ArrayList.add(ArrayList.java:351)
at de.lessvoid.nifty.elements.tools.TextBreak.processWords(TextBreak.java:47)
at de.lessvoid.nifty.elements.tools.TextBreak.split(TextBreak.java:24)
at de.lessvoid.nifty.elements.render.TextRenderer.bla(TextRenderer.java:394)
at de.lessvoid.nifty.elements.render.TextRenderer.setWidthConstraint(TextRenderer.java:407)
at de.lessvoid.nifty.elements.Element.processLayoutInternal(Element.java:563)
at de.lessvoid.nifty.elements.Element.processL(Element.java:569)
at de.lessvoid.nifty.elements.Element.processL(Element.java:583)
at de.lessvoid.nifty.elements.Element.processL(Element.java:583)
at de.lessvoid.nifty.elements.Element.processL(Element.java:583)
at de.lessvoid.nifty.elements.Element.processL(Element.java:583)
at de.lessvoid.nifty.elements.Element.layoutElements(Element.java:597)
at de.lessvoid.nifty.screen.Screen.layoutLayers(Screen.java:185)
at net.malrix.debaclemmo.ChatAreaController.setText(ChatAreaController.java:85)
at net.malrix.debaclemmo.ChatAreaController.append(ChatAreaController.java:75)
at net.malrix.debaclemmo.DebacleGUI.displayMessage(DebacleGUI.java:110)
at net.malrix.debaclemmo.DebacleClient.simpleInitApp(DebacleClient.java:276)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:218)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:136)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:193)
at java.lang.Thread.run(Thread.java:662)
BUILD SUCCESSFUL (total time: 8 seconds)

Here are the methods called:



public void displayMessage( String message ) {
//chatArea.append( message.replace( " ", "-" ) );
chatArea.append( message );


public void append( String text ) {
String curText = getText( );
if( curText.isEmpty( ) ) {
setText( text );
} else {
setText( "n" + text );

public void setText( String text ) {
textArea.getRenderer( TextRenderer.class ).setText( text );

screen.layoutLayers( );

public String getText( ) {
return textArea.getRenderer( TextRenderer.class ).getOriginalText( );

Thanks for taking a look, let me know if you need more details.

I patched in a bunch of the changes to TextBreak.java and TextRenderer.java from 1.3 and it now displays text correctly in my basic tests. I’m looking forward to the 1.3 release, I’m on to other things for now.