Corrupted texture when loading 3ds object in simpleUpdate()


I’m having a bit of texture problem in my new project. I’ve built a ModelRepository that loads my 3ds models into memory the first time they are requested, then simply cloned for each successive request to that model. It works fine when calling from simpleInitGame(), but as soon as I add a model from simpleUpdate(), the texture gets corrupted when viewing from certain angles.

The upper right jet is added via simpleInitGame(), no problems there. The lower one is added via simpleUpdate(), seems fine…

Here, I’ve simply turned the camera towards the lower jet in the above screenshot (and moved closer so you could more easily see the letters that makes up the texture now). I’ve added SpatialTransformers to rotate the jets, so this one has rotated a bit from last screenshot. Tried removing the SpatialTransformers as well, same corruption in texture.

Does anyone have any ideas on this? I’m really stumped.

I’m running jME 0.8 and jdk 1.5.0, here’s my ModelRepository class:

public class ModelRepository {
   private static HashMap<String, CloneCreator> models = new HashMap<String, CloneCreator>();
   private ModelRepository() {

   public static Spatial getModel(String path, String model) {
      String p = path + "/" + model;
      CloneCreator result = null;
      if (models.containsKey(p)) {
         result = models.get(p);
      } else {
         try {
            FormatConverter converter = new MaxToJme();
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            JmeBinaryReader jbr = new JmeBinaryReader();
            URL texpath = new File(System.getProperty("user.dir") + "/models/" + path + "/").toURL();
            //URL texpath = ModelRepository.class.getClassLoader().getResource();
            jbr.setProperty("texurl", texpath);
            URL modelpath = new File(System.getProperty("user.dir") + "/models/" + p).toURL();
            converter.convert(modelpath.openStream(), bo);
            jbr.setProperty("bound", "box");
            Spatial s = jbr.loadBinaryFormat(new ByteArrayInputStream(bo.toByteArray()));
            result = new CloneCreator(s);
            models.put(p, result);
         } catch (IOException e) {
            System.out.println("WARNING: Exception while loading " + p + ": " + e.getMessage());
            models.put(p, null);
      if (result == null) {
         //TODO: Return a cube or something
      return result.createCopy();

Call updateRenderStates() on your loaded/cloned node.

This is not needed in simpleInitGame() as updateRenderStates() is called on the rootNode after invocation of the init method. That's why it works in this case.

Calling updateRenderState() on the Spatial before returning worked perfectly. Thank you!