Varying loading times

Here I am again good people…



Does anybody experienced huge loading times with jme native binary models (.jme?) sometimes? I recently started having this very anoing issue. All my models are converted from .obj (exported from blender) to .jme. Sometimes the game loads very fast… But sometimes it gets stuck at the loading line:



public static Node loadModel(String model) {
      try {
         System.out.println(0);
         URL urlModelo = ModelUtil.class.getClassLoader().getResource(model);
         System.out.println(1);
         BufferedInputStream br = new BufferedInputStream(urlModelo.openStream());
         System.out.println(2);
         Node no = new Node();
         no.attachChild((Spatial) BinaryImporter.getInstance().load(br));
         System.out.println(3);
         no.setModelBound(new BoundingBox());
         no.updateModelBound();
         System.out.println(4);
         return no;
      } catch (IOException e) {
         e.printStackTrace();
      }
      return null;
   }



I've put the sysouts to debug the exact moment of the stuckness... And it's between the 2 and three, at the lines:

Node no = new Node();
         no.attachChild((Spatial) BinaryImporter.getInstance().load(br));



Anyway, the most strangest thing is that the load time changes awfully from time to time, without changing a single line of code or any model. I didn't manage to track what were the differences in the computer... I can't find any reason and becoming a bit mad with it already.

Thanks in advance

And since I can see this:


23/Ago/2007 19:29:29 com.jme.scene.Node <init>
INFO: Node created.



It means the problem happens at the loading line...

I forgot to scary people... The time difference is HUGE... Miliseconds when ok, and something like 30 or more seconds/model when not ok. It happens even when I try to load an already loaded model.

I might have the same problem - after updating from cvs today (apparently I hadn't actually compiled the 1.0rc1 yet!) my app seems to hang during startup, possibly during model loading. I'll investigate further and post my results.

So run it with debugging enabled, or even better, with a profiler running. Maybe it's hanging on just one method?

Gotcha!!!



SimpleResourceLocator… It tries to traverse the directory tree to find the file… And there's an issue when it gets the Grandpa of the file… It concatenates a "/" at the beggining of the file name, and if that name already starts with a "/", it becomes a "//resourceName", which forces some systems to check for the resource as a NETWORK computer or something… Now I see, It was intermitent because it happened everytime I was connected…



Here is the bad-method-guy (at SimpleResourceLocator):


protected String trimResourceName(String resourceName) {
        File f = new File(resourceName);
        if (f.getParentFile() != null) {
            File grandpa = f.getParentFile().getParentFile();
            if (grandpa != null) {
                return grandpa.toString().concat("/").concat(f.getName());
            } else {
                return f.getName();
            }
        }
        return null;
    }



To make it correct, just add a test to check if there's need to concatenate the last "/" (sorry, I'm too sleepy to think a better algorithm):

protected String trimResourceName(String resourceName) {
        File f = new File(resourceName);
        if (f.getParentFile() != null) {
            File grandpa = f.getParentFile().getParentFile();
            if (grandpa != null) {
               String grandpaName = grandpa.toString();
               if (!grandpaName.endsWith("/"))
                  grandpaName = grandpaName.concat("/");
                return grandpaName.concat(f.getName());
            } else {
                return f.getName();
            }
        }
        return null;
    }



Am I right? Worked for me... And sorry, I don't know how to make a patch yet.
perick said:

And sorry, I don't know how to make a patch yet.


diff file1.txt file2.txt > patch.txt

;) ... If you run windows.... cygwin is a very good emulator, you know ;)

@SeySayux: Man, I am deeply disappointed  :smiley: Being an outspoken Linux fan, cygwin is not an emulator (it is not an acronym  :P)  :wink: it is an environment implementation.

commited.

@duenez: yes I know, but you shouldn't talk with too much tech-talk to newbies… I'm a Linux fan too, you know (maybe it's only because I cannot afford a Mac, and that Mac isn't opensource… hmm… opensource free mac clone… sounds like an idea… meh, that's called baghira :wink: )

yes I know, but you shouldn't talk with too much tech-talk to newbies...


Hey, r u calling me newbie? In what sense? Because I didn't know how to make a patch? Hehehe, my mistake, but I' not afraid of any tech-talk. I guess nobody here (except me) already implemented a network distributed fault-tolerant layer for the Ext2 filesystem directly in the Linux kernel. I don't think that was newbie job. :)
perick said:

yes I know, but you shouldn't talk with too much tech-talk to newbies...


Hey, r u calling me newbie? In what sense? Because I didn't know how to make a patch? Hehehe, my mistake, but I' not afraid of any tech-talk. I guess nobody here (except me) already implemented a network distributed fault-tolerant layer for the Ext2 filesystem directly in the Linux kernel. I don't think that was newbie job. :)


Too much of a noobie to do full Ext3 support? :-p

I don't think there was any negative connotation meant (by him), it's just in general too much should not be assumed to the level of computer competency from other users.
I don't think there was any negative connotation meant (by him),

I didn't take it as negative. :) I'm just trying to have as much fun as you guys have with replies.

Too much of a noobie to do full Ext3 support? :-p

Ext3 was still beta when I implemented that (some BigInteger time ago).

Anyway, thanks everybody for the awesome tool (jme) and even better comunity.
perick said:

Ext3 was still beta when I implemented that (some BigInteger time ago).


Damn!, it must have been before Unix epoch (on January 1, 1970 for the n00bs  :P), since a 32 bit integer is not enough to account for it  ;)

I don't know much people that write extensions to the linux kernel, but that don't know how to use diff/patch or how to read a manpage ;)  :stuck_out_tongue: . Btw, darkfrog is right.

I'm used to manpages, I just didn't have the need to use diff/patch before… So many other things I didn't do…:slight_smile: