Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset paths that begin with "/" don't work on Android #352

Closed
shadowislord opened this issue Sep 24, 2015 · 4 comments · Fixed by #1577
Closed

Asset paths that begin with "/" don't work on Android #352

shadowislord opened this issue Sep 24, 2015 · 4 comments · Fixed by #1577
Labels
Android defect Something that is supposed to work, but doesn't. Less severe than a "bug"
Milestone

Comments

@shadowislord
Copy link
Member

Due to the changes in jME 3.1 to use Android's AssetManager instead of the ClasspathLocator, paths that begin with a forward slash no longer work.

@shadowislord shadowislord added the bug Something that is supposed to work, but doesn't. More severe than a "defect". label Sep 24, 2015
@shadowislord shadowislord added this to the 3.1 milestone Sep 24, 2015
@zzuegg
Copy link
Member

zzuegg commented Sep 24, 2015

Rather strange, there is already some code in the AndroidLocator to remove a leading /

@nordfalk
Copy link

nordfalk commented Nov 8, 2016

OK, I have used several days on this one!

Here is what extensive debugging finally brought to me.
As you can see from https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-android/src/main/resources/com/jme3/asset/Android.cfg the com.jme3.asset.plugins.AndroidLocator gets as / as path:

# Android specific locators
LOCATOR / com.jme3.asset.plugins.AndroidLocator

This means that the locator gets rootPath = "/" .... and now look at

public AssetInfo locate(AssetManager manager, AssetKey key) {
, in the case where the AssetKey starts with a "/" (like "/Textures/...")

String assetPath = rootPath + key.getName(); // will start with TWO slashes, like "//Textures/...

The // Fix path issues will remove ONE of the slashes, but not the other, which will make the system look in the root of the Linux Android file system :-(

Proposed fix 1: Avoid / as path

# Android specific locators
LOCATOR . com.jme3.asset.plugins.AndroidLocator

(best would be to set rootPath = "" but that isnt possible as it would not be valid syntax)

Proposed fix 2: ... or change to a while loop instead of an if statement:

  // Fix path issues
        while (assetPath.startsWith("/")) {
            // Remove leading /
            assetPath = assetPath.substring(1);
        }

Proposed fix 3: replace "//" with "/" before removing heading slash

        assetPath = assetPath.replace("//", "/");
        if (assetPath.startsWith("/")) {
            // Remove leading /
            assetPath = assetPath.substring(1);
        }

This bug affects all people that uses the SDK terrain editor (jMonkeyEngine 3.1-beta1-b002-SNAPSHOT) as it wrongly puths forward slashes in the paths of the textures in the .j3o file.

See also discussions

@nordfalk
Copy link

nordfalk commented Nov 8, 2016

Until this is fixed in the source the easiest workaround for the wrong path in the AndroidLocator is probably to unregister the locator with the wrong path and register it again with an empty path before you load the scene

        assetManager.unregisterLocator("/", AndroidLocator.class);
        assetManager.registerLocator("",AndroidLocator.class);

        Spatial scene = assetManager.loadModel("Scenes/myScene.j3o");

@stephengold stephengold added duplicate This issue is a duplicate of a previously reported issue. and removed duplicate This issue is a duplicate of a previously reported issue. labels Jun 24, 2021
@stephengold
Copy link
Member

Closed by PR #1577.

@stephengold stephengold modified the milestones: 3.1, Future Release Jun 24, 2021
@stephengold stephengold added defect Something that is supposed to work, but doesn't. Less severe than a "bug" and removed bug Something that is supposed to work, but doesn't. More severe than a "defect". labels Jun 24, 2021
@stephengold stephengold linked a pull request Jun 24, 2021 that will close this issue
@stephengold stephengold modified the milestones: Future Release, v3.5.0 Oct 23, 2021
@stephengold stephengold modified the milestones: v3.5.0, v3.4.1 Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android defect Something that is supposed to work, but doesn't. Less severe than a "bug"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants