[Solved - kind of]Unregister a FileLocator

I use a FileLocator to load from a directory. However, I allow the user to change the name of the directory at runtime (I rename the folder). On the next call to assetManager.loadWhatever() (yes, loading whicever type crashes the app), I get this:

Exception in thread "Thread-7" java.lang.IllegalArgumentException: Given root path "D:\JME3 Projects\LSF Blueprint Builder\ships\A pod" is not a directory
	at com.jme3.asset.plugins.FileLocator.setRootPath(FileLocator.java:54)
	at com.jme3.asset.ImplHandler$ImplThreadLocal.initialValue(ImplHandler.java:119)
	at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:180)
	at java.lang.ThreadLocal.get(ThreadLocal.java:170)
	at com.jme3.asset.ImplHandler.tryLocate(ImplHandler.java:177)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:359)
	at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:390)
	at com.jme3.asset.DesktopAssetManager.loadTexture(DesktopAssetManager.java:400)
	at com.grizeldi.lsfmobile.appstates.MainMenuAppState$1.run(MainMenuAppState.java:99)
	at java.lang.Thread.run(Thread.java:745)

In this case the old directory name was “A Pod” and new one was “Bloxxel”.
I think the problem here is that assetManager tries to look into the folder which has in the meantime disappeared. So how would I remove a FileLocator?

EDIT: Ignore this, I’m stupid :cry:. For future people, there is assetManager.unregisterLocator(). :rolling_eyes: <— this sadly doesn’t work :frowning:
EDIT2: Unregistering the locator did not fix it though. Seeking help still.

So here, I solved the problem, but I found a “bug” related to forward and backward slashes.
So I registered the FileLocator with someFile.getParent() as a root path parameter. When printing that out it printed .\ships\Test. I wanted to remove the locator without creating a file. So the root path string was ./ships/Test. That did not successfully remove the locator.
So maybe a feature-request to enable forward-slash to backward slash conversion?

You have to remove it with the same string you added it with.

Though, I’m starting to feel like we should just throw an IllegalArgumentException whenever a file String is passed anywhere with backward slashes in it. Would solve a lot of problems. Let the user normalize their own file names.

2 Likes