I’m new to jMonkeyEngine and relatively new to NetBeans. I’m trying to build a NetBeans Platform Application with jME3 embedded, but I seem to be running into very basic problems. For instance, if I create a new application and add a new Action that starts the jME3 HelloWorld example, I run into this error when I click on the Action in my application menu:
[java]java.lang.IllegalStateException: Cannot run from EDT
at com.jme3.system.JmeDesktopSystem.showSettingsDialog(JmeDesktopSystem.java:101)
at com.jme3.system.JmeSystem.showSettingsDialog(JmeSystem.java:118)
at com.jme3.app.SimpleApplication.start(SimpleApplication.java:124)
at aero.sei.awtpanels2.StartHelloWorld.actionPerformed(StartHelloWorld.java:26)[/java]
@ActionID(
category = “Tools”,
id = “aero.sei.awtpanels2.StartHelloWorld”) @ActionRegistration(
displayName = “#CTL_StartHelloWorld”) @ActionReference(path = “Menu/Tools”, position = 0) @Messages(“CTL_StartHelloWorld=Start HelloWorld”)
public final class StartHelloWorld implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
HelloJME3 app = new HelloJME3();
app.start(); // start the game
}
}[/java]
Despite extensive Googling and reading through the forums and online documentation, I still can’t make heads or tails of how to get jME3 to work with a NetBeans RCP application effectively. I would appreciate any advise the community can provide.
The error description says what the problem is: The jME application cannot be started from the EDT, thats the Event Dispatch Thread of AWT which for example executes the button press actions.
Generally… The jME SDK is a NetBeans RCP application so you have source code that you could look at for the integration. Depending on what you want to do and what your experience is you might be in for quite the headache though. AWT threading being one of the most problematic things generally.
@icamefromspace said:
just a guess by reading the error. before you do app.start() you need to do app.setShowSettings(false).
Well, that certainly helped. Why does showing the settings window produce an error?
Interestingly, I noticed that this works if I call setShowSettings(false) in the Action class before app.start() or in the HelloJME3 constructor. However, it doesn’t work if I call it in the simpleInitApp() class in HelloJME3. Why is this?
@normen said:
The error description says what the problem is: The jME application cannot be started from the EDT, thats the Event Dispatch Thread of AWT which for example executes the button press actions.
Generally… The jME SDK is a NetBeans RCP application so you have source code that you could look at for the integration. Depending on what you want to do and what your experience is you might be in for quite the headache though. AWT threading being one of the most problematic things generally.
I admit that my knowledge of threading is not nearly as strong as it should be. Would I need to run my jME on a separate thread from the rest of the application, or can it all be on the same thread? Is there a good tutorial somewhere on threading in jME in situations like this?
I did spend some time looking through the source code, although it’s not quite as well-documented in places as I would like, and I had some trouble navigating it. Can you point me to some sections of the code that would be useful for Netbeans RCP integration?
Thanks again. This is all helping me gain a much better conceptual understanding of what’s going on programmatically.
@JCSW said:
Well, that certainly helped. Why does showing the settings window produce an error?
Interestingly, I noticed that this works if I call setShowSettings(false) in the Action class before app.start() or in the HelloJME3 constructor. However, it doesn’t work if I call it in the simpleInitApp() class in HelloJME3. Why is this?
the value read you set in setShowSettings(false) is used before simpleInitApp() is called. simpleInitApp() is called after the game loop is already running. so you must call that method before app.start()
I’m guessing youre not supposed to use it in the EDT because the settings window would hold up the EDT (and i think this means the buttons youd push on the settings window woudlnt do anything, since the EDT is being held up). Additionally I’m sure the jmonkey application has some assumptions of being run on its own thread. I could imagine there would be difficulties if say, the EDT closed for instance.
Even if there wasnt the technical problems of the settings window here, it wouldnt be what you wanted any way as the settings window doesnt provide relevant options to whats going on.
as for your second set of questions, what I think normen is saying is that you use jmonkey with netbeans, you’d start the jmonkey application instance in the main() method. you’d probably only use the EDT to enqueing events to your jmonkey appliaction.
You may want to search the SDK source code for instances where these methods are used: app.createCanvas(), app.startCanvas(), and app.start(JmeContext.Type.Canvas); to see how the sdk actually does it.
disclaimer: A lot of what I’m saying is just speculation, I haven’t actually worked on the jme sdk.
Thanks again. I spent a lot of time yesterday reviewing threading, queuing, and callbacks, plus reviewing more of the source code, so I think I have a better idea of what’s going on in terms of threading.
I ran into another problem with my application, which I’ve posted about in this thread here. I would appreciate any insight anybody has on this, since it seems to be a very obscure error having to do with threading and repainting.