Newbie Program Structure issues

Here’s an example of something I tried… I created an object to store my player information in, including the node that the player would be attached to, and a box to represent my player until I get around to doing something else for that end… I created these in the constructor.

In initSimpleGame I add the players node to the graph but it doesn’t work, doesn’t matter where the constructor for the player object is called from, it simply fails… the same code works fine, if I make an init() function and moved my constructor code there, and then called that. I guess I’m more curious than anything, why would the first version fail, is Object construction in java done on a seperate thread or something? Is this intentional for jME to ignore the nodes created in the constructor example?

well to answer your question. Objects are not created in another thread. I the program fails you should have a stacktrace. Try posting that and your code :smiley:

You mean objects are not allowed to be created in another thread, or that in the case i described objects are not being created in another thread?

I can see both being true.

There is no limitation on object creation and threads. That said, you do have to understand what is going on in your threads and how they comingle or data may not be there when you expect.

If you are just creating something in simpleInitGame though, you are not using a seperate thread.

As was stated, code and stack traces would allow us to investigate.

This is a chunk out of the HelloWorld applet, can go in basically any simple game. In this example init() is called from the PlayerObject constructor, however, if the line in the constructor is commended out, and used in the smipleInitGame instead, it works. In both situations all objects should be getting created at the same time in the same order, but somehow this example simply doesn’t work (but switching where init is called does work).

PlayerObject player;
protected void simpleInitGame() {
player = new PlayerObject();



This is the player class

public class PlayerObject {
public Node playerNode;
Vector3f location = new Vector3f(0f,0f,0f);
public void PlayerObject() {

public void init() {
playerNode = new Node("Player Node");
Box b = new Box("Player char",
new Vector3f(0f,0f,0f),
new Vector3f(1f,1f,1f));
b.setModelBound(new BoundingBox());

The problem is that you think you have a Constructor for PlayerObject, but in reality you have made it a regular method by giving it a return type (void in this case.) Thus, the default constructor inherited from Object is being used and your init call is never made. Make your constructor:

public PlayerObject() {

Also, fwiw, the HellowWorld class is not an applet. jME applications can not currently be run in the browser as applets. Hope this helps.

Calling it an applet was um, a typo. My call to init works fine if it’s made from simpleGameInit, however, if it is made from the constructor of player instead, it fails. The order of operations should still be the same regarding jme, nodes are created and added to in the same order, the only differences is when init is called in the constructor, instead of in simpleGameInit (immediately after creating the new object). It acts like the node is never created or attached though no visible errors occur.

I feel stupid, I didn’t quite catch your meaning on playerobject… I suspected it had to be a stupid mistake, thanks for catching it. I almost went with some print statements but I figured there was no where I could go wrong there… I think I’ll go sit in a corner and suck my thumb for a bit.

edit: Didn’t the compiler used to give an error if you named a method the same as a class but had a return value, I’m positive it used to (kind of like when you try to override an existing method but change return types)?

That’s cool. Most IDEs will flag this… I’m kinda surprised if the compiler doesn’t at least give a warning. At least mystery solved though. :slight_smile:

I use JCreator… it basically provides some file management, formatting shortcuts… and most important, pretty text with lucida console for a font… course, i realize i’m crazy for using it… just about everyone uses eclipse (I don’t have any idea why I don’t… I tried it and was impressed but still it’s not on my machine).

just about everyone uses eclipse

You should too ... it rocks hehe.

Back on topic :wink:

When I had textures loaded in a separate thread it failed when making GL11 calls. It happened in TextureManager when calling apply on the TextureState, which tried create the texture IDs and killed the entire JVM. This seems like a LWJGL issue though.

Texture’s have to be loaded on the same thread as the opengl context, when working with jogl I’d have a queue for textures that were requested but not loaded yet and at the start of drawing I would load the new texture files.

This seems like a LWJGL issue though.

It's more of an OpenGL issue as Dan implied. All OpenGL calls must[b] be called in the same thread that created the OpenGL context.