NiftyGUI on Android

Hi there!

I’m really confused about this, because i think i’ve done everything right.
I want to create some Nifty GUI.
Here is the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<nifty xmlns:xsi="" xmlns="" xsi:schemaLocation="">
<useControls filename="nifty-default-controls.xml"/>
<useStyles filename="nifty-default-styles.xml"/>
<screen id="start" controller="tower.WorldState">
    <layer id="GLayer0" childLayout="absolute">
        <control name="label" id="GLabel0" width="82px" x="9" y="11" text="HP: 50" font="aurulent-sans-16.fnt" height="26px"/>
        <control name="label" id="GLabel1" width="82px" x="9" y="24" text="SCORE: 0" font="aurulent-sans-16.fnt" height="38px"/>

As you can see, nothing fancy here.

And in an AppState I do the following:

public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app); = app;
    NiftyJmeDisplay disp = NiftyJmeDisplay.newNiftyJmeDisplay(Assets.manager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort());
    nifty = disp.getNifty();
    nifty.fromXml("Interface/ingame.xml", "start", this);

On my desktop this works wonderfully, but on my (little bit old, Sony Xperia U, Android 4.0.3) Android phone i get the following exception right at startup:

E/dalvikvm-heap( 3656): Out of memory on a 16777232-byte allocation.
I/dalvikvm( 3656): "GLThread 861" prio=5 tid=11 RUNNABLE
I/dalvikvm( 3656):   | group="main" sCount=0 dsCount=0 obj=0x4158aec0 self=0x16de918
I/dalvikvm( 3656):   | sysTid=3674 nice=0 sched=0/0 cgrp=default handle=23426176
I/dalvikvm( 3656):   | schedstat=( 9109161344 1914367710 12563 ) utm=848 stm=62 core=0
I/dalvikvm( 3656):   at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
I/dalvikvm( 3656):   at java.nio.MemoryBlock.allocate(
I/dalvikvm( 3656):   at java.nio.ReadWriteDirectByteBuffer.<init>(
I/dalvikvm( 3656):   at java.nio.ByteBuffer.allocateDirect(
I/dalvikvm( 3656):   at com.jme3.util.BufferUtils.createByteBuffer(
I/dalvikvm( 3656):   at com.jme3.niftygui.JmeBatchRenderBackend.createTextureAtlas(
I/dalvikvm( 3656):   at de.lessvoid.nifty.render.batch.BatchRenderDevice.createTextureAtlas(
I/dalvikvm( 3656):   at de.lessvoid.nifty.render.batch.BatchRenderDevice.createInitialTextureAtlases(
I/dalvikvm( 3656):   at de.lessvoid.nifty.render.batch.BatchRenderDevice.<init>(
I/dalvikvm( 3656):   at com.jme3.niftygui.NiftyJmeDisplay.<init>(
I/dalvikvm( 3656):   at com.jme3.niftygui.NiftyJmeDisplay.newNiftyJmeDisplay(
I/dalvikvm( 3656):   at tower.WorldState.initialize(

Without these few lines the whole app runs fine.
Am i missing something trivial about it (as usual)? Or what should i check?
Any help would be appriciated.

Just looking at the stacktrace, I get a feeling that the batched Nifty renderer’s default image size might be too big. Try making it smaller. The default size was 2048x2048 I think. Try 512x512 etc.

Thank you, you were absolutely right! I did not know where i could change that, but some googleing helped.
For future readers:

    BatchRenderConfiguration conf = new BatchRenderConfiguration();
    conf.atlasHeight = 256;
    conf.atlasWidth = 256;
    NiftyJmeDisplay disp = NiftyJmeDisplay.newNiftyJmeDisplay(Assets.manager(), app.getInputManager(), app.getAudioRenderer(), app.getGuiViewPort(), conf);

Again, thank you. :slight_smile: