Add, Remove, ReAdd InputListeners,Mappings and Triggers

Hello,



I add InputListeners, Mappings and Triggers and they work as expected. Within my Netbeans program I have the possibility to switch between multiple scenes. There is one Application object but if I switch between two scenes I must remove all nodes, InputListeners, Triggers and Mappings, Audio etc. When I perform such a switch (or only deactive one scene and activate it again) the InputListeners do not react anymore. My questions are as following…



Do I have to take care for the sequence I add InputListeners, Mappings and Triggers?

Do I have to take care for the sequence I remove InputListeners, Mappings and Triggers?

Do I have to reinit something after adding and/or removing?



Everything is performed in the RenderQueue of course.



Thanks a lot for help.

JMonkyEngine rules.



Regards,

Equi

Yep, you probably change the scenegraph from the AWT Event Dispatch Thread (the main AWT thread). You have to wrap everything in callables or use an AppState or something as callback from the OpenGL thread like I do in jMP to modify scene data.

Normally not, if you just add and remove them when appropriate it should work, I guess its something in your code. jMP adds and removes input listeners each time a different plugin (e.g. SceneComposer, TerrainEditor) takes over the scene.

Hello,



I have figured out the problem. It is again (my long term friend)…



Update exception. Scene graph is not properly updated for rendering.

Make sure scene graph state was not changed after

rootNode.updateGeometricState() call.

Problem spatial name: CrystalScene 671862692487168

[Ljava.lang.StackTraceElement;@1894800



I suppose, that I have to call



[java]

rootNode.updateGeometricState();

[/java]



after adding the scene tree to the root node again, but I thought this is done automatically within the render loop.



Thanks.



Regards,

Equi

It is done automatically as part of the render loop.



The cases where you run into this:

  1. you are modifying the scene graph outside of the update loop (ie: from another thread)
  2. you are modifying the scene graph in some control’s or app state’s render call.
  3. the root node you are using is not the same one that your Application is calling updateGeometricState() on… ie: you’ve setup your own viewport with its own root node or something.
1 Like

@pspeed

completely agree

Hello,



when exactly do I have to use AppStates and what are they used for. What is the difference to the enqueue method of Application?

Thanks.



Regards,

Equi

Read these pages:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:application_states

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:multithreading