SaveGame.saveGame() isn’t working anymore for me (16 posts)

  • Profile picture of glaucomardano glaucomardano252p said 3 months, 2 weeks ago:

    It worked before, I don’t know what’s going on. My jmp is up to date. I do:

    SaveGame.saveGame("kinetrax/musics", "Musics", track.getAudioNode().getParent().getParent().getParent());
    

    And it throws this exception :

    java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    	at java.lang.String.charAt(String.java:695)
    	at java.util.regex.Matcher.appendReplacement(Matcher.java:761)
    	at java.util.regex.Matcher.replaceAll(Matcher.java:905)
    	at java.lang.String.replaceAll(String.java:2210)
    	at jme3tools.savegame.SaveGame.saveGame(SaveGame.java:41)
    	at kinetrax.nifty.control.screen.soundeditor.SoundEditorScreenControl.save(SoundEditorScreenControl.java:135)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at de.lessvoid.nifty.NiftyMethodInvoker.callMethod(NiftyMethodInvoker.java:145)
    	at de.lessvoid.nifty.NiftyMethodInvoker.performInvoke(NiftyMethodInvoker.java:104)
    	at de.lessvoid.nifty.Nifty$DelayedMethodInvoke.perform(Nifty.java:1176)
    	at de.lessvoid.nifty.Nifty.invokeMethods(Nifty.java:1154)
    	at de.lessvoid.nifty.Nifty.handleDynamicElements(Nifty.java:312)
    	at de.lessvoid.nifty.Nifty.access$1500(Nifty.java:73)
    	at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processEvent(Nifty.java:1371)
    	at de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl.processMouseEvent(Nifty.java:1329)
    	at com.jme3.niftygui.InputSystemJme.onMouseButtonEventQueued(InputSystemJme.java:121)
    	at com.jme3.niftygui.InputSystemJme.forwardEvents(InputSystemJme.java:313)
    	at de.lessvoid.nifty.Nifty.update(Nifty.java:248)
    	at com.jme3.niftygui.InputSystemJme.endInput(InputSystemJme.java:90)
    	at com.jme3.input.InputManager.processQueue(InputManager.java:1485)
    	at com.jme3.input.InputManager.update(InputManager.java:1702)
    	at com.jme3.app.Application.update(Application.java:595)
    	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:236)
    	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:178)
    	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:225)
    	at java.lang.Thread.run(Thread.java:722)
    
  • Profile picture of normen normen1290p said 3 months, 2 weeks ago:

    you sure your node name doesn’t contain any special characters? also try using a slash before the path maybe if that doesn’t work.

  • Profile picture of pspeed pspeed815p said 3 months, 2 weeks ago:

    I think this line will fail on Windows:
    File daveFolder = new File(JmeSystem.getStorageFolder().getAbsolutePath() + File.separator + gamePath.replaceAll(“/”, File.separator));

    Maybe try replace() instead of replaceAll().

    At least my memory says that replaceAll() accepts escapes in the second parameter and so the File.separator on Windows would need to be double-escaped.

  • Profile picture of pspeed pspeed815p said 3 months, 2 weeks ago:

    Specifically:
    gamePath.replace( ‘/’, File.separatorChar )

    …which would also avoid the internal regex creation. Though that’s not really a performance issue in this case… it is unnecessary.

    I assume this path must be used to compare to actual system paths or something? Otherwise, this replacement isn’t even needed. Java file IO should properly use “/” as a file separator on any platform. It’s only when you need to do comparison with retrieved File paths that it matters.

  • Profile picture of glaucomardano glaucomardano252p said 3 months, 2 weeks ago:

    Thanks, problem solved. And yes, it didn’t contain any special characters, and the solution was doing :

    SaveGame.saveGame("kinetrax", "Musics", track.getAudioNode().getParent().getParent().getParent());
    

    instead of :

    SaveGame.saveGame("kinetrax/musics", "Musics", track.getAudioNode().getParent().getParent().getParent());
    

    Btw, it worked before…

    Ah, and putting a slash like this

    /kinectrax

    doesn’t work too.

    @pspeed: hmmm, yeah, I’m running it on windows.

  • Profile picture of douter douter14p said 2 months, 3 weeks ago:

    Looks like the “java.lang.StringIndexOutOfBoundsException: String index out of range: 1″ is a known bug in java

    See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6523151

    Thread: http://stackoverflow.com/questions/1049103/why-am-i-getting-a-stringindexoutofboundsexception-when-i-try-to-replace-wi

    Btw. is it ok that…

        public static BinaryImporter getInstance() {
            return new BinaryImporter();
        }

    … always returns a new instance?

  • Profile picture of pspeed pspeed815p said 2 months, 3 weeks ago:

    That’s not a bug. You have to double escape the in the replacement string because of the possibility of substitution.

    But really, if you are just replacing one character with another then there is 0 reason to use replaceAll() when a much cheaper replace() does exactly what you’d want.

  • Profile picture of douter douter14p said 2 months, 3 weeks ago:

    @pspeed The replaceAll is used in the SaveGame class

    Check TestSaveGame for usage.

    Escaping doesn’t work in this case.

    Btw. is it ok that…

        public static BinaryImporter getInstance() {
            return new BinaryImporter();
        }

    … always returns a new instance?

  • Profile picture of pspeed pspeed815p said 2 months, 3 weeks ago:

    @douter said:
    @pspeed The replaceAll is used in the SaveGame class

    Check TestSaveGame for usage.

    Escaping doesn’t work in this case.

    Yes, SaveGame is busted. But Java isn’t.

    SaveGame starts up the Mac truck, loads it up with 500 tons of carrots, and then drives down to the foot of the driveway just to get a piece of mail from the mailbox.

    (In this metaphor, the part of the Mac truck was played by the Java regex infrastructure and the part of the trip down the driveway is played by the really simple and fast 0-overhead replace() call.) :)

  • Profile picture of normen normen1290p said 2 months, 3 weeks ago:


    !=

    ;)

    As paul said, we just need to use replace() here.

  • Profile picture of pspeed pspeed815p said 2 months, 3 weeks ago:

    You have my type “mac” so many times that my fingers don’t know how to type “mack” anymore. :) (But now I have the Convoy song running through my head again… ;) )

  • Profile picture of normen normen1290p said 2 months, 3 weeks ago:

    .. I just replaced the image with the “real” Mack from Rubber Duck ^^

  • Profile picture of pspeed pspeed815p said 2 months, 3 weeks ago:

    @normen said:
    .. I just replaced the image with the “real” Mack from Rubber Duck ^^

    I wondered what had happened.

    …and now we’ve just about buried this thread. :)

  • Profile picture of normen normen1290p said 2 months, 3 weeks ago:

    Anything interesting going on here else? xD

  • Profile picture of douter douter14p said 2 months, 3 weeks ago:

    What about the BinaryImporter?