Bug in AssetKey, including fix

[java]protected static String getFolder(String name)

{

int idx = name.lastIndexOf(’/’);

if (idx <= 0 || idx == name.length() - 1)

return “”;

else

return name.substring(0, idx+1);

}

[/java]



is unavare of the possibility of other given file-separators.

please change to:



[java]protected static String getFolder(String name)

{

String strFolder = “”;

// standard behaviour

int idx = name.lastIndexOf(’/’);

if (idx > 0 && idx != name.length() - 1)

strFolder = name.substring(0, idx+1);

if (strFolder.length() > 0 || File.separatorChar == ‘/’)

return strFolder;

// check for system dependent separator char

idx = name.lastIndexOf(File.separatorChar);

if (idx > 0 && idx != name.length() - 1)

strFolder = name.substring(0, idx+1);

return strFolder;

}

[/java]

AssetManager locations do not use File.separator but just normal slashes.

look into sollution again, it could easily use both and become system-independent

You are still not getting the AssetManager, hm? ^^ Its not a system path, it has nothing to do with folders on your disk, its the asset path and it only uses slashes, even if it loads a file from your disk. Class paths also use only slashes even when you build your app on windows :wink:

On my system, its currently used for far more than that;-)



i provide an xml-file with a special loader that contains all my textures including description and pathes to files. those may be provided by system interaction, and that – on windows – may return backslashes.





There is reason in Java.io providing File.separatorChar;-)

Dude, you’re not getting it. The AssetManager is your filesystem and it only uses slashes. Period. Look at FileLocator, it converts the locations to the correct version for the current OS filesystem to load from folders.

If you feed the assetmanager some windows path you derive from a file you have to convert all backslashes to slashes because it (intentionally) does not use these kinds of paths, its behaving more like a classloader.

Normen is correct, the AssetManager essentially provides a system-independent, virtualized file system that uses forwardslash/unix-style separators.