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.

https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_physics.html

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();
    
    app.start();
           
    SerialCommunication serialComm = new SerialCommunication(app);
    serialComm.initialize();
}

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).

app.makeCannonBall();

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.

http://www.thegreenhead.com/2007/05/big-red-button-doomsday-device-usb-hub.php

Thanks ahead of time!

-Justin

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

https://jmonkeyengine.github.io/wiki/jme3/advanced/multithreading.html

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?

https://jmonkeyengine.github.io/wiki/jme3/advanced/input_handling.html

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.