Texture failed when createTextureState in simpleUpdate [Jme2]

Hi

This is a sample which works as expected:

[java]

package hunter.client;



import java.net.URL;



import com.jme.app.SimpleGame;

import com.jme.bounding.BoundingBox;

import com.jme.bounding.BoundingSphere;

import com.jme.image.Texture;

import com.jme.light.PointLight;

import com.jme.math.Vector3f;

import com.jme.renderer.ColorRGBA;

import com.jme.scene.Node;

import com.jme.scene.shape.Box;

import com.jme.scene.shape.Sphere;

import com.jme.scene.state.LightState;

import com.jme.scene.state.MaterialState;

import com.jme.scene.state.TextureState;

import com.jme.util.TextureManager;



public class Main extends SimpleGame

{

public static void main(String[] args)

{

Main app = new Main();

app.setConfigShowMode(ConfigShowMode.AlwaysShow);

app.start();

}



private Box b;



protected void simpleInitGame()

{

if(b == null)

{

// Create our objects. Nothing new here.

b = new Box(“My box”, new Vector3f(1, 1, 1), new Vector3f(2, 2, 2));

b.setModelBound(new BoundingBox());

b.updateModelBound();





// Get a URL that points to the texture we’re going to load

URL monkeyLoc;

monkeyLoc = Main.class.getClassLoader().getResource(

“goblin.jpg”);



// Get a TextureState

TextureState ts = display.getRenderer().createTextureState();

// Use the TextureManager to load a texture

Texture t = TextureManager.loadTexture(monkeyLoc,

Texture.MinificationFilter.BilinearNearestMipMap,

Texture.MagnificationFilter.Bilinear);

// Assign the texture to the TextureState

ts.setTexture(t);



// Signal that b should use renderstate ts

b.setRenderState(ts);

rootNode.attachChild(b);

}

}



protected void simpleUpdate()

{



}

}



[/java]





But if I move the code to simpleUpdate, the texture will fail:

[java]



package hunter.client;



import java.net.URL;



import com.jme.app.SimpleGame;

import com.jme.bounding.BoundingBox;

import com.jme.bounding.BoundingSphere;

import com.jme.image.Texture;

import com.jme.light.PointLight;

import com.jme.math.Vector3f;

import com.jme.renderer.ColorRGBA;

import com.jme.scene.Node;

import com.jme.scene.shape.Box;

import com.jme.scene.shape.Sphere;

import com.jme.scene.state.LightState;

import com.jme.scene.state.MaterialState;

import com.jme.scene.state.TextureState;

import com.jme.util.TextureManager;



public class Main extends SimpleGame

{

public static void main(String[] args)

{

Main app = new Main();

app.setConfigShowMode(ConfigShowMode.AlwaysShow);

app.start();

}



private Box b;



protected void simpleInitGame()

{



}



protected void simpleUpdate()

{

if(b == null)

{

// Create our objects. Nothing new here.

b = new Box(“My box”, new Vector3f(1, 1, 1), new Vector3f(2, 2, 2));

b.setModelBound(new BoundingBox());

b.updateModelBound();





// Get a URL that points to the texture we’re going to load

URL monkeyLoc;

monkeyLoc = Main.class.getClassLoader().getResource(

“goblin.jpg”);



// Get a TextureState

TextureState ts = display.getRenderer().createTextureState();

// Use the TextureManager to load a texture

Texture t = TextureManager.loadTexture(monkeyLoc,

Texture.MinificationFilter.BilinearNearestMipMap,

Texture.MagnificationFilter.Bilinear);

// Assign the texture to the TextureState

ts.setTexture(t);



// Signal that b should use renderstate ts

b.setRenderState(ts);

rootNode.attachChild(b);

}

}

}

[/java]







Should textures not be created in simpleUpdate ?

If so where should I create textures when I want to dump the old scene and create a new one in the game?

Thank very much for your time!

sorry, its a very stupid question~

I just forgot [java]b.updateRenderState(); [/java]