Gui Node not attached to anything?

The box was using a wireframe material and it was 10 by 10.



I played your game for a little bit (Mythruna) and it has a “3d” model on the gui (the one when you choose a model to place). Is that a jme3 project? and if so, how did you get a 3d object to render on the guiNode, what format was it?

The wireframe material won’t help you debug your lighting issues. I still think it’s the material and lighting setup that are messed up so you should use the same material and light for your cube test.



Yes, Mythruna is a JME project.



I don’t put 3D objects on the JME guiNode because anything that requires proper z-buffering looks all ugly and the perspective gets stripped out. I did try it.



I have tried it again recently for the inventory screen but I opted for a second overlay ViewPort instead… since I could do real 3D in that.



And all of my objects are build in-game and not from standard models. The player avatar being the only 3D asset that I actually load.

1 Like
@pspeed said:
I don't put 3D objects on the JME guiNode because anything that requires proper z-buffering looks all ugly and the perspective gets stripped out. I did try it.

I have tried it again recently for the inventory screen but I opted for a second overlay ViewPort instead... since I could do real 3D in that.


I should note that once I had the light setup right and the position and scale right, they did render. I just didn't like the way they looked.
1 Like

Another viewport would be a good way, then you can have it in all its 3 dimensional glorious sexiness

So how do you OVERLAY a second 3D viewport? I’ve seen them side by side.

You have to do special stuff to get them to sit side by side. Otherwise, they are already overlaying.



You just have to manage your viewport yourself. I post an app state that can do it somewhere… teh googlez says here:

http://test.hub.jmonkeyengine.org/groups/graphics/forum/topic/can-i-render-an-object-ontop-of-everything-but-under-gui/?topic_page=2&num=15

1 Like

remove the test part from the link, n it will work :). Even i have used multiple overlaying viewports, so by de facto anyone can do it :slight_smile:

Updated link:

http://hub.jmonkeyengine.org/groups/graphics/forum/topic/can-i-render-an-object-ontop-of-everything-but-under-gui/?topic_page=2&num=15

Sorry. I guess the google search box thingy is a little overzealous in what it searches or it is misconfigured somehow.



Thanks for fixing the link.

1 Like

Thanks for the information guys.



I tried implementing pspeed’s viewportstate but I am having a few issues with it,



This is the ViewPortState.java

(I removed the override on the init because it produced an error)



[java]package client;



import com.jme3.app.Application;

import com.jme3.app.state.AbstractAppState;

import com.jme3.light.DirectionalLight;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.renderer.RenderManager;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial.CullHint;



public class ViewPortState extends AbstractAppState {

private Camera g_cam;

private ViewPort g_view;

private Node g_root;



public ViewPortState() {

}



public Node getRoot() {

return g_root;

}



public Camera getCamera() {

return g_cam;

}



protected void initialize( Application app )

{

g_root = new Node( “guiview Root” );

g_root.setCullHint(CullHint.Never);

Camera originalCam = app.getCamera();

g_cam = new Camera(originalCam.getWidth(), originalCam.getHeight());

g_cam.setFrustumFar(1000f);

g_view = app.getRenderManager().createMainView(“guiview”, g_cam);

g_view.setEnabled(true);

g_view.setClearFlags(false, true, false);

g_view.attachScene( g_root );

DirectionalLight light = new DirectionalLight();

light.setDirection( new Vector3f( 1, 0.2f, -1.5f ).normalizeLocal() );

g_root.addLight(light);

g_root.updateLogicalState(1);

g_root.updateGeometricState();

}



@Override

public void render(RenderManager rm) {

g_root.updateGeometricState();

}



@Override

public void update( float tpf ) {

g_root.updateLogicalState(tpf);

}



}[/java]



I connect my hands to them here (… indicating other code removed for space, already posted before, this is in the initplayer section)



[java]Node gui_root;



gui_root = app.getStateManager().getState(ViewPortState.class).getRoot();



gui_root.attachChild(handsnode);[/java]



After doing that, if I attempt to run my project, i get the error:



[java]Mar 19, 2012 7:13:27 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at client.object_player.initPlayer(object_player.java:57)

at client.Main.simpleUpdate(Main.java:136)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

at client.Main.update(Main.java:91)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

BUILD SUCCESSFUL (total time: 5 seconds)[/java]



But I can’t find where the nullpointer comes from, but, I have a feeling it has to do with the initialize not being overridden and then g_root doesn’t equal anything when I try to set gui_root to it.



I don’t know how to solve this as when I put @Override at the initialize, it gives me an error (concerning it not being a method of the supertype)



What do I do guys? -.-

The initialize() method signature was wrong in my version. By removing the @Override you merely hid the problem the compiler was telling you about… thus your initialize() is never called by StateManager because it isn’t the right method.



Change the initialize() method to match the one in the super class… put the @Override back… and things should work.

1 Like

Thank you, that solved the NullPointerError for that, but now i’m getting another issue (God, i’m so bad at this 8O ).



The error that occurs is this:



[java]Mar 19, 2012 11:26:38 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at client.object_player.init_handgui(object_player.java:79)

at client.Main.simpleUpdate(Main.java:155)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

at client.Main.update(Main.java:91)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

BUILD SUCCESSFUL (total time: 6 seconds)[/java]



This is the ViewPortState.java file:



[java]package client;



import com.jme3.app.Application;

import com.jme3.app.state.AbstractAppState;

import com.jme3.app.state.AppStateManager;

import com.jme3.light.DirectionalLight;

import com.jme3.math.Vector3f;

import com.jme3.renderer.Camera;

import com.jme3.renderer.RenderManager;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial.CullHint;



public class ViewPortState extends AbstractAppState {

private Camera g_cam;

private ViewPort g_view;

private Node g_root;



public ViewPortState() {

}



public Node getRoot() {

return g_root;

}



public Camera getCamera() {

return g_cam;

}



@Override

public void initialize(AppStateManager stateManager, Application app)

{

g_root = new Node( “guiview Root” );

g_root.setCullHint(CullHint.Never);

Camera originalCam = app.getCamera();

g_cam = new Camera(originalCam.getWidth(), originalCam.getHeight());

g_cam.setFrustumFar(1000f);

g_view = app.getRenderManager().createMainView(“guiview”, g_cam);

g_view.setEnabled(true);

g_view.setClearFlags(false, true, false);

g_view.attachScene( g_root );

DirectionalLight light = new DirectionalLight();

light.setDirection( new Vector3f( 1, 0.2f, -1.5f ).normalizeLocal() );

g_root.addLight(light);

g_root.updateLogicalState(1);

g_root.updateGeometricState();

}



@Override

public void render(RenderManager rm) {

g_root.updateGeometricState();

}



@Override

public void update( float tpf ) {

g_root.updateLogicalState(tpf);

}



}[/java]



This is where the error is occuring:



[java] public void init_handgui(SimpleApplication app)

{

gui_root = app.getStateManager().getState(ViewPortState.class).getRoot();

hands = Main.api.getAssetManager().loadModel(“Models/hands.j3o”);

hands.scale(1f);

handsnode = Main.spawn.create_model(Main.api, new Vector3f(100,100,1), hands, “01ddf”);

handsnode.setLocalTranslation(100,100,1);

gui_root.attachChild(handsnode);

}[/java]



(Line 79 is the gui_root.attachChild part)



This is the interface setup:



[java]public void start_interface(SimpleApplication app)

{

app.getGuiNode().detachAllChildren();

app.getStateManager().attach(new ViewPortState());



}[/java]



(Other code removed for space saving)



and this is the load order:



[java]play.initPlayer(this);



gi.start_interface(this);

play.init_handgui(this);[/java]



Not entirely sure whats going on here…



Sounds as if handsnode doesn’t exist/isn’t being initialized, but it is in the init_handgui, just before I try to attach it…

Maybe that’s the pit I encountered to be a little counterintuitiv, too. Initialize is not called after attaching a state. It is first called in the first updateCycle after it’s attachement. Maybe that’s why this returns null.

Hm, after that being said, I changed it to:



[java]public void start_interface(SimpleApplication app)

{

app.getGuiNode().detachAllChildren();

app.getStateManager().attach(new ViewPortState());

app.getStateManager().getState(ViewPortState.class).initialize(app.getStateManager(), app);



}[/java]



and I now get the error:



[java]Mar 20, 2012 12:20:56 AM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.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: guiview Root

at com.jme3.scene.Spatial.checkCulling(Spatial.java:241)

at com.jme3.renderer.RenderManager.renderScene(RenderManager.java:768)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1109)

at com.jme3.renderer.RenderManager.render(RenderManager.java:1160)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:266)

at client.Main.update(Main.java:91)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

BUILD SUCCESSFUL (total time: 7 seconds)[/java]



In the thread linked before, pspeed mentions that (in response to a similar error) I should have:


Somewhere in your app setup, call getStateManager().attach( new ViewPortState() );


of which I do, right above the initialise :?

This is terribly confusing.

You do not call initialize yourself. In case I read that right in your last message.



If you want to use the root node earlier then you can instantiate it in the viewport state’s constructor. Just don’t do any of the other stuff until initialize.



I’ve decomposed my app into app states. I forget that others still do tons of logic during simpleInit(). Since all of my stuff is in app states, by the time my game app state is called the other app states have already been initialized.

1 Like

No Idea why I didn’t think of that, thank you so much pspeed! It works now.



The only problem is, I can’t seem to get the camera to point at the hands/ the hands to render.



I can’t reference the camera at any point as I keep getting nullpointererrors.



Also, I do pretty much nothing in simpleInit, except setting some variables for the interface, the whole loading part here is using the nifty loading states.



If it’s not too much trouble, here are the three problematic files:



Main.java

object_player.java

ViewPortState.java



If someone can look at these and try and figure what the issue is, because I have no idea. Maybe I should go back to text based games :roll:

You can create your camera early, too.

1 Like

You mean setting it in the constructer with:



[java]private Camera g_cam = new Camera();[/java]



?



I tried that and it still produced an error when I try this code in the init_handgui:



[java]app.getStateManager().getState(ViewPortState.class).getCamera().lookAt(handsnode.getLocalTranslation(), cam.getUp());[/java]



Edit:



The error being:



[java]Mar 20, 2012 2:32:04 AM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at client.object_player.init_handgui(object_player.java:78)

at client.Main.simpleUpdate(Main.java:155)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

at client.Main.update(Main.java:91)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

BUILD SUCCESSFUL (total time: 6 seconds)[/java]



and I used lookat just to try and get it to see if the hands were in the scene or not.

I don’t believe you or there is some piece you are leaving out.



If g_cam gets set in ViewPortStates constructor and getCamera() is returning that camera then the only way you will get an NPE on that line is if it is not related to the camera at all… either handsnode is null or the viewport state has not really been attached yet.



It occurs to me that this kind of thing is about the single easiest thing to track down simply by running the debugger or printing some variables to the console. If you can’t figure out an NPE just by looking at it then figure out which reference is null using debug printlns or something.



In this line:

app.getStateManager().getState(ViewPortState.class).getCamera().lookAt(handsnode.getLocalTranslation(), cam.getUp());



6 different references could be null. app, getState(), getCamera(), handsnod, cam. Takes 15 seconds to figure out which. I can only guess, though.

1 Like

All of my code is up on the GoogleCode site, which i’m guessing you haven’t looked at whenever I link it judging by the tone of your previous posts.



There is two null values in that line, gui_root and cam. I’m trying to solve cam but i’m not sure what to do about gui_root.



gui_root should not be null, and it makes no sense to as why it is null. I’m confused. This is the ENTIRE block that it is in.



[java]public void init_handgui(SimpleApplication app)

{

gui_root = app.getStateManager().getState(ViewPortState.class).getRoot();

hands = Main.api.getAssetManager().loadModel(“Models/hands.j3o”);

hands.scale(1f);

handsnode = Main.spawn.create_model(Main.api, new Vector3f(0,0,0), hands, “01ddf”);

System.out.println("1 " + gui_root);

System.out.println("2 " + hands);

System.out.println("3 " + handsnode);

System.out.println("4 " + cam);

System.out.println("5 " + app);

System.out.println("6 " + app.getStateManager().getState(ViewPortState.class).getCamera().toString());

app.getStateManager().getState(ViewPortState.class).getCamera().lookAt(handsnode.getLocalTranslation(), cam.getUp());

gui_root.attachChild(handsnode);

}[/java]



and this is the “error” it produces:



[java]1 null (Node)

2 hands-objnode (Node)

3 hands-objnode (Node)

4 null

5 client.Main@47098a

Mar 20, 2012 3:09:24 AM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.renderer.Camera.getDirection(Camera.java:606)

at com.jme3.renderer.Camera.toString(Camera.java:1383)

at client.object_player.init_handgui(object_player.java:83)

at client.Main.simpleUpdate(Main.java:155)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:258)

at client.Main.update(Main.java:91)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:149)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:182)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:223)

at java.lang.Thread.run(Thread.java:662)

BUILD SUCCESSFUL (total time: 6 seconds)[/java]



By the looks of it, it’s not getting to 6, the grabbing the app camera. I’m really not sure how to go about debugging this…