HelloPhysics problem firing cannonball from different class

I’m pretty good at programming in Java but I’m new to jMonkeyEngine. I’ve gotten everything installed and the HelloPhysics example at the link below works great. My goal is to modify this example so that another class can call the “makeCannonBall()” method in the example code. I ultimately want an Arduino to send a serial message to this class when a button is pushed, and have the class fire the cannonball.


I got my new class to work over serial, when new data is received an event occurs causing this method to run.

This is the main method in the HelloPhysics example:

public static void main(String[] args) 
    Main app = new Main();
    SerialCommunication serialComm = new SerialCommunication(app);

In the second class the constructor is:

public SerialCommunication(Main app)
    this.app = app;     

In the second class this line is executed (in the event handler for new data received).


The line above produces an error:

Uncaught exception thrown in Thread[jME3 Main,5,main]
IllegalStateException: Scene graph is not properly updated for rendering.
State was changed after rootNode.updateGeometricState() call.
Make sure you do not modify the scene from another thread!
Problem spatial name: Root Node

So my question is how am I supposed to accomplish this in jMonkey?

I tried creating another class that extended AbstractAppState but that didn’t work. In this class I tried to call makeCannonBall() and update the geometric state before/after but I couldn’t get it to do anything. I basically created this class object in main, had the new class create a SerialCommunication object serialComm, then had serialComm call a method in the AppState class that would fire the cannon ball and update. I’m not sure if this would or even could have worked. It’s possible I did it wrong but I unfortunately deleted the class so I can’t post it. If this is the route I have to go I’d appreciate code examples but I’ll take any advice I can get.

O and if your wondering what this is for its the start of my Doomsday box project. I want to make a really cool machined enclosure fit with controls, timer, keypad, buzzer, buttons, and more that basically controls a simple game that goes boom and resets. Its kind of stupid but I saw something like it online (link below) and figured I’d make my own new and improved version.


Thanks ahead of time!


Presumably your serializer thing is on another thread and the error message you get is dead-accurate. If so…


I’m probably exposing my ignorance on the subject but this looks like nothing more than a joystick. Cant you extend BaseAppState and just implement a JoystickEventListener?


No because that is no standardized USB Joystick using DirectInput/XInput.
He would have to override some Engine Parts for the Input Backend.

Something which I can recommend though, because he can use any game/the jme standard way then to handle input.

Hmm I think that what psspeed mentioned is probably what I need to do. I’ll try that later and see how it goes.

I hadn’t thought of utilizing the Arduino as an input device but it could work. I have an Arduino Yun and a Due which have the capability to be setup to act as a keyboard/joystick/mouse over usb rather than a serial port.

Anyway thanks for the input, I’ll post again if I run into trouble.