Loading 2 xml at the same time cause a freeze (java heap memory )

Hi guys ,



i’m trying to load a menu and a log window that is writting what the menu does when i push enter , the thing is that when i try to load the 2 xml ( 1 xml for menu and 1 xml for log ) i have a Freeze when i push a button to browse the menu.



I’m using nifties examples here , chatareacontroller and chatcontroller for the log windows , and menuitemmapping menuitemcontrol for the menu.



I’m loading the 2 xml like this :





SimpleinitApp(){



Setupinterface1();

Setupinterface2();

}



with Setupinterface1 and 2 ( nifty.loadfromxml(“file.xml”);



when i click with the mouse on the menu items , it’s working very fine and i have what i want on the chat log ( according to onclick on xml ).



My guess is that the input controller is trying to load the same ressource than the log window that’s why it’s freezing , like an infinite loop.



Suggestions are welcome ,



thank you

Hi momoko_fan , and thanks for reading this ,



This is what i have :



[java]



public void SetupInterface() {





NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);



guiViewPort.addProcessor(niftyDisplay);

guiNode.detachAllChildren();

nifty = niftyDisplay.getNifty();

nifty.fromXml("Interface/log.xml", "start");

}



public void SetupInterface2() {



NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);



guiViewPort.addProcessor(niftyDisplay);

guiNode.detachAllChildren();

/*

  • Picture pic = new Picture("HUD Picture"); pic.setImage(assetManager,
  • "Textures/Interface/icone.png", false);
  • pic.setPosition(settings.getWidth()/2, 0); guiNode.attachChild(pic);

    */

    nifty = niftyDisplay.getNifty();

    nifty.fromXml(“Interface/menu.xml”, “start”);

    }



    [/java]



    and this is what i do :



    [java]



    @override

    public void simpleInitApp(){

    SetupInterface();

    SetupInterface2();

    }

    [/java]



    I did that because i don’t know how to load two screen at the same time on a nifty xml file.



    The issue here is that when i select an item from my menu , i have the corresponding of what i’m doing on the log window (the goal i want ) , but if i do this with arrows it will hang up ( by default arrow can browse the menu ) otherwise if i just push enter to select the item it will also work … that’s a very strange problem…

You cannot create two nifty objects like this.

Please look at the nifty gui documentation on how to handle your use case. You do not need two screens to have separate log and menu.

Okay , But there have separate controller , how am i suppose to add several controller on only 1 screen ?

What do you mean by at the same time? You are aware that button pushes are distributed via the AWT thread and that multiple threads have implications that you have to handle, right?

by the same time i mean that i’m loading 2 xml nifty with 2 each controller / xml in simpleinitapp , and that cause that i can’t use the keyboard anymore or the game will freeze . What do you mean by button pushes ? I’m using my own graphics and it’s working well if i click with a mouse on the item menus. I use a thread to write into the chat menu btw.

Are you by any change using two Nifty objects? Or are you calling loadFromXml on the same Nifty object?

Thank you lutherion , that’s what i’m trying to do , but how do you load multiples screen at the same time ? i’m doing a menu and a chat log , when i push enter on a menu item i have on the chat log " you pushed a button " . For that i did 2 xml 1 for the chat and 1 for the menu , i need them together at the same time , they each have 2 controllers . I want to do as your way but i don’t know how to load 2 screens at the same time of having only 1 screen that having multiples controllers…

i stil didn’t find out how multiples controllers can be on the same screen by nifty , is someone knows please tell me.

A complete GUI must be coded in one file for nifty, and there can only be one! I think nifty or your code is not thread safe, so you get a endless loop. Try to code the whole gui you want at a time in one nifty-xml-file.

I didn’t make nifty dev since last september, but if i remember right you can define controller for the elements not only for the complete file. Furthermore you should be able to include your self written nifty components(in a seperate file) into the master file by defining and using it as a component.

You don’t load multiple screens at the same time, you only have one with the needed components.

With the findControl method in nifty-screen-class you can connect the controller objects to do what’s needed.

Look into the nifty component declarations(.xml source) to see how it is made. You only have one screen controller but many component controller.

A Nifty <screen, > and its associated ScreenController controls all elements that are visible at a certain time. I think of this more like states: A screen for each state of your Application GUI. Like a screen for the start menu, a screen for your in game option menu, a screen for your ingame GUI overlay and so on.



You can have multiple screens in one xml file and you can switch between those screens.



You can’t have multiple screens visible at the same time even when they would cover separate areas.



Nifty does currently not have a “include other xml file” option directly. What you can do however, is what Lutherion suggested: Create a custom control for each of your components. You can include them with the <useControls …> tag which actually works like an “include this xml file” in the end.



A Nifty control can be both, a new control (like in the progressbar tutorial) or you can simply use it as a xml template. A controller for that kind of controls is not required!



The Nifty tutorial/demo thing I did for the 1.2 Release did use “controls” to simply define the pages you can scroll through. Adding a <controlDefinition…> for each individual page and switching from page to page by dynamically adding a new page while removing the old one. Maybe take a look at the tutorial example xml source as well as the ScreenController for an example.



Just imagine the <controlDefinition…> would be named <xml-snippet…> or so when you want to use it like that :slight_smile:



If you have a more complicated “something” you can add a controller to the control - like in the progressbar example. Again, this is not required to be a “simple” control it could be bigger like a dialog or a collection of individual controls. The example I’m working on for the Nifty 1.3 Release will infact use a controlDefinition for a complete Dialog that consists of several buttons, textfields and so on.