I have written a separate GUI part in Swing for my game. So when the player sets his user name and other settings, this Java application starts the other one using the exec() method. The problem is my game crashes immediately after startup, throwing out messages I only saw when binding native DLLs with JNI.

My other application (the game) does this: it loads all the settings and other stuff, then it creates a JFrame. The error occurs in the JFrame constructor, right before I call super():

public Game() { super("My game");

This is the code I'm using to start the game:Process proc = Runtime.getRuntime().exec( new String[] {"javaw", "-cp", "bin;.", "com.mygame.Game"}, new String[] {"dd"}, new File("D:\\Tgame2"));

Local Time = Tue Sep 12 18:10:56 2006Elapsed Time = 1## The exception above was detected in native code outside the VM## Java VM: Java HotSpot(TM) Client VM (1.4.2_04-b05 mixed mode)## An error report file has been saved as hs_err_pid4144.log.# Please refer to the file for further information.#

As you can see from the first two lines, the game is working in the beginning (loading settings), but then it crashes when it needs to create a new JFrame. Also, the error is apparently in D:\Java\jre\bin\awt.dll

Any idea how I can fix this? Is there something special regarding to loading other Java GUI applications?

Why are you running these as two different processes? Why not have the initial gui be part of the same process as your game? If you need to, run them in different threads. Generally speaking you're heading down the wrong path if your internally developed app is two different processes running at the same time.

I've tried the same thing before. Runtime.exec() seemed to work for non-Java programs, but not for Java or any program that used Java's VM.

I don't know what the problem is. Maybe both processes are trying to use the same instance of the virtual machine. Different windows of an Internet browser share the VM for multiple instances of the same applet, so maybe this is a similar issue.

I never resolved the problem when I was using Runtime.exec, but I did figure out that if I didn't use any static variables to store game state in the applet that I could run multiple instances of the same applet at the same time.

The point is that you are going to spend a lot of time trying to do something that is completely unnecessary. I doubt anyone here has run into this problem, because it is not something that would be tried. You can just put Game game = new Game(); game.run(); instead of trying to invoke a new process.

The point is that you are going to spend a lot of time trying to do something that is completely unnecessary. I doubt anyone here has run into this problem, because it is not something that would be tried. You can just put Game game = new Game(); game.run(); instead of trying to invoke a new process.

Actually, no, I cannot do that. The reason why I started this whole process thing was because I couldn't start the game frame with Game game = new Game(); because then the newly created frame never becomes the focusOwner(), and my code requires that to be able to draw.

]Notice the line where it says if (isFocusOwner()); this will never be true. For some reason Swing needs a few seconds to initialize the JFrame, and only then it will become the focus owner. So if I comment out the loop() the window will show up and actions will be handled properly. But the loop() won't get started and the game is not played.If the loop() is not commented out, it will just continue forever, and the window will never be drawn

This way it will work, but since loop() is called from another thread, the drawing is slow, it stops from time to time etc.

I even tried EventQueue.invokeLater(), and it again worked like this, but now the mouse and the keyboard weren't reacting.

As it stands now, the game only works when it is started as a stand-alone application. Then it is the focusOwner() and the keyboard and the mouse are reacting properly. It didn't help that after the game was started I disposed of the Swing window, or that I've set the Game frame toFront()

So the only option I could think of was starting the game as a stand-alone application by another Java application, but it seems I can't do that either

I know one solution would be to draw everything on the same JFrame, but I would really rather like to have separate code. One where I setup the game, and another one where I play it.

It's hard to say what you've really got going without taking a hard look at your code. But my hunch is you've kinda dug yourself into a hole. Anytime you find yourself doing something unusual like trying to launch another process, that's usually a red flag that your in trouble.

Getting Java2D to work with games can be difficult. You might consider backing off a bit. Taking your core logic code and building a new framework around it. Try to keep it simple.

Well I can provide the entire game code in a ZIP file if anyone's interested in taking a look at it

There's really no reason for me to back off now. The game as it is works fine. I even started writing the client/server part. It draws out whatever I want the way I want. In other words, the "engine" is almost finished. From now on I can just add elements to the game and it would work.

I always have problems with Swing in situations like this. I remember once in a client/server application I had the login dialog, which would then create a thread which would display the logo and do additional checks, and then create another thread which would display the main application frame. Except that in that case I wasn't worried about FPS's

One of the reasons why I decided to make a game in Java was the thought of not having problems with making my own GUI, because I could simply relly on Swing... and now I've lost a whole day trying to figure this out...

I had similar (?) problem some time ago. I was writing an eclipse plugin, and I needed to launch an external program from it. In fact I needed to launch a batch file (".bat"), containing just a line like:

Anyway I decided that wasting one day on this was enough. Now I start the game with parameters like this:game --mode single --server yes --user csaba --password 12345 --window yes --map 3In the end I'll write a GUI in Delphi or C++ which will then just pass the parameters to the game and that's it.

Oh yeah, and I noticed there was an error in the code I posted previously. I must have accidentally deleted fpsCounter++ beneath the while (gameRunning) line. Anyway, it didn't change a thing.

I always have problems with Swing in situations like this. I remember once in a client/server application I had the login dialog, which would then create a thread which would display the logo and do additional checks, and then create another thread which would display the main application frame. Except that in that case I wasn't worried about FPS's

Unless you're using active rendering, multiple threads in combination with awt/swing is a recipe for disaster. Since neither is tread safe, you're bound to bump into race conditions and/or deadlocks sooner or later. Btw, I don't see why you would need to create a thread to show a splash screen or new window.As someone already said, it's hard to give more constructive feedback without knowing exactly what you're doing. My gut feeling says threading issues. You might be blocking the EDT by starting the game loop on it. You might be drawing to a Graphics object from a non-EDT thread, which gives kind of unpredictable results, ...

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org