Partile Emitter, mainNode, rootNode.updateGeometricState()

When action button is pressed a partial emitter is created and then it is attached to the mainNode, which is then attached to the rootNode.(this is due to the water processor).



But when I attached this code, the following error appears.



java.lang.IllegalStateException: Scene graph is not properly updated for rendering.

Make sure scene graph state was not changed after

rootNode.updateGeometricState() call.

Problem spatial name: null

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

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

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

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

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

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

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

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

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



But If I attached the particle emitter directly to the rootNode, this problem goes away. But, i want to attach it to the mainNode.



I have the following two line at the start of the simpleUpdate function,(i am using ray casting to determine on which object the player is standing)

[java] rootNode.updateLogicalState(tpf);

rootNode.updateGeometricState();[/java]



If I add [java]mainNode.updateGeometricState();[/java] after the particle emitter is attached to the mainNode, then the following error appears

java.lang.NullPointerException: Geometry: Emitter has null mesh
at com.jme3.scene.Geometry.updateWorldBound(Geometry.java:180)
at com.jme3.scene.Spatial.updateGeometricState(Spatial.java:647)
at com.jme3.scene.Node.updateGeometricState(Node.java:185)
at mygame.Main.throwFireball(Main.java:465)
at mygame.Main$3.onAction(Main.java:418)
at com.jme3.input.InputManager.invokeActions(InputManager.java:145)
at com.jme3.input.InputManager.onMouseButtonEvent(InputManager.java:337)
at com.jme3.input.lwjgl.LwjglMouseInput.update(LwjglMouseInput.java:106)
at com.jme3.input.InputManager.update(InputManager.java:486)
at com.jme3.app.Application.update(Application.java:448)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:194)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)
at java.lang.Thread.run(Thread.java:619)

ok, somehow, updateXXX issue has been solved.



Now for the actual problem, I am using actionListener, like the following

[java]if(binding.equals(“CharFreeRotate”))

{

if(isPressed)

{

freeRotate = true;

}

else

{

freeRotate = false;

rotatePlayer();

}

}[/java]

and the method is

[java] public void throwFireball()

{

pe_fire = new ParticleEmitter(“Emitter”, Type.Triangle, 30);

Material mat_red = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);

mat_red.setTexture(“m_Texture”, assetManager.loadTexture(“Effects/Explosion/flame.png”));

pe_fire.setMaterial(mat_red);

pe_fire.setImagesX(2); pe_fire.setImagesY(2); // 2x2 texture animation

pe_fire.setEndColor( new ColorRGBA(1f, 0f, 0f, 1f)); // red

pe_fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow

pe_fire.setInitialVelocity(new Vector3f(0, 7, 0));

pe_fire.setStartSize(2.5f);

pe_fire.setEndSize(.1f);

pe_fire.setGravity(0);

pe_fire.setLowLife(0.5f);

pe_fire.setHighLife(2.75f);

pe_fire.setVelocityVariation(0.3f);

pe_fire.setRandomAngle(true);

pe_fire.setRotateSpeed(5);



SphereCollisionShape cs_fire = new SphereCollisionShape(2);

pn_fire = new PhysicsNode(pe_fire, cs_fire, 1);

pn_fire.setLocalTranslation(-300, 11, 122);

pn_fire.setGravity(new Vector3f(0,-1,0));

pn_fire.applyForce( pn_fire.getLocalTranslation().subtract(pn_player.getLocalTranslation()).mult(30).negate(), pn_fire.getLocalTranslation());

pe_fire.emitAllParticles();

pn_fire.attachDebugShape(assetManager);

mainNode.attachChild(pn_fire);

bulletAppState.getPhysicsSpace().add(pn_fire);

}[/java]



But, when the action takes place, following error occures

java.lang.NullPointerException: Geometry: Emitter has null mesh

at com.jme3.scene.Geometry.updateWorldBound(Geometry.java:180)

at com.jme3.scene.Spatial.checkDoBoundUpdate(Spatial.java:494)

at com.jme3.scene.Geometry.collideWith(Geometry.java:244)

at com.jme3.scene.Node.collideWith(Node.java:502)

at com.jme3.scene.Node.collideWith(Node.java:502)

at mygame.Main.updateStandingOnRay(Main.java:900)

at mygame.Main.simpleUpdate(Main.java:731)

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

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

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

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

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





But, if i use rootNode instead of mainNode, the code runs, but, doesn’t perform as it supposed to.

Like physics shapes collide with the charcter, but, their debug shape is not visible, and some time the come out of thin air(!!!) and at Vector3f.ZERO those particle appears along with the flying balls. But, they shouldn’t be there.

Try removing the updateXXX lines from your simpleUpdate(), they should not be needed anymore.

I am using raycasting and to determing wherer the player is standing, If i remover those lines, the a new error occures.

java.lang.IllegalStateException: Scene graph must be updated before checking collision

That error is incorrect and shouldn’t be there, since we added local scene graph updates.

I fixed it and removed the error in last revision, so you no longer need to call updateGeometricState() to check collision

[java] standingOnRayResults = new CollisionResults();

standingOnRay = new Ray(new Vector3f(pn_player.getLocalTranslation().getX(), pn_player.getLocalTranslation().getY()-3f,pn_player.getLocalTranslation().getZ()), Vector3f.UNIT_Y.negate());

mainNode.collideWith(standingOnRay, standingOnRayResults);



if(standingOnRayResults.size() != 0 & pn_player.onGround())

standingOnRayString = standingOnRayResults.getClosestCollision().getGeometry().getName();

else

standingOnRayString = “nothing”;[/java]



this code doesn’t word unless I add “updateGeometryStatic()”… :?



Is this the line, that is causing the main problem?(i cannt add particle emitter on another node except rootNode)

You might have to add updateGeometricState() to update the physics state … I am not sure about that, perhaps normen knows better

No, physics doesnt use updateGeometricState anymore.

Ok, i have tried by removing all the updateXXX from my code, but still, the errors of the ‘first post’ remains.



any idea? :?

Okay then you’re gonna have to give us more detail. I removed the usage of updateGeometricState() in the official jME collision/picking tests and they work fine without it.

iamcreasy said:
When action button is pressed [..]

I hope this doesnt mean you directly do the call from the AWT thread then? Wrap it to be executed from the OpenGL thread when you want to do this in the buttonPressed method:
[snippet id="10"]