Strange problem with FileLocator and dynamic language


I’m using the dynamic language Clojure to make a jME3 game. Things run fine, until the following happened…

I have the code:

[java](doto (.getAssetManager app) (.registerLocator “assets/” (.getName FileLocator)))[/java]

which is equivalent to

[java]app.getAssetManager().registerLocator(“assets/”, FileLocator.class.getName())[/java]

(not sure exactly about that getName() but I think it doesn’t matter).

The reason for me having a FileLocator in the first place is that I couldn’t find my assets otherwise, but now it works (hmm, why?).

If I change “assets/” to “srternh/” or something that doesn’t exist, it doesn’t work anymore. No surprise there. The strange thing is that if I change it back to “assets/” it still doesn’t work. Well, when I say it doesn’t work, what I mean is that when I redefine everything, it doesn’t work. What is happening is that the JVM does not stop at any time, and the old stuff just gets GCed. I create a new instance of everything. I checked that the program works by running it in a new JVM from the command line. Without changing the “assets/” string and then back again, I can rerun the program, making new instances of everything in the same JVM.

I was just wondering if anyone knows or has any ideas of what could be happening. And I want to work like this without restarting the JVM all the time because it’s the natural way to work with Clojure. Is there anything that you know don’t work well if I don’t restart the JVM, just making new instances of everything and try again?

I hope you understand what I’m trying to say, if not, ask me to clarify. And if you want to see my Clojure code it is here: It may be hard to read if you don’t know Clojure, but it’s short and using a lot of java stuff; I think you should be able to figure it out. Also, Clojure is really nice, you should try it. :slight_smile:

Its not actually FileLocator.getClass() as that would be a syntax error. The proper way is FileLocator.class which returns a Class object. I think what you’re looking for then is [java](.class FileLocator)[/java]

FileLocator is already a Class object in Clojure. I changed the code above. But that was not the problem, it works when I don’t mess with the path string…

So you might say “don’t do that then” but I wanna know what’s wrong, I’m concerned.

I am not sure, but can you try using File.getCanonicalPath() for this? It might be more direct than specifying a path relative to the working directory

File.getCanonicalPath() didn’t make any difference, it still works just as before.

Perhaps it has to do with the AssetManager. How is it initialized? Is it singleton or something similar? Well, it still dosen’t make a lot of sense because if I have the correct path from the beginning, and then change it, it stops working. So it notices the change. But, if I change it back it doesn’t start working again.

Sounds like its time for you to take out the debugger and see what’s happening under the hood …