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

Resource finding is not robust #316

Open
danielhaaser opened this issue Apr 9, 2013 · 1 comment
Open

Resource finding is not robust #316

danielhaaser opened this issue Apr 9, 2013 · 1 comment
Labels

Comments

@danielhaaser
Copy link

There are some corner cases in which certain directory structures will not work with CocosBuilder. The problem lies with the relativePathFromAbsolutePath method in ResourceManagerUtil.

Here's an example of a project setup that's broken:

cocosbuilder-directory-structure

cocosbuilder-resource-settings

When I set a sprite frame to be a resource in the "Cocosbuilder Raw Assets Android" directory, the relativePathFromAbsolute path returns a bad relative path. The issue lies with "Cocosbuilder Raw Assets Android" having the same prefix as the "Cocosbuilder" directory in which the project file lives.

+ (NSString*) relativePathFromAbsolutePath: (NSString*) path
{
    NSArray* activeDirs = [[ResourceManager sharedManager] activeDirectories];

    for (RMDirectory* dir in activeDirs)
    {
        // Old Code
        //NSString* base = dir.dirPath; 

        // New Code
        NSString* base = [NSString stringWithFormat:@"%@/",  dir.dirPath];  

        if ([path hasPrefix:base])
        {
            // Old Code
            //NSString* relPath = [path substringFromIndex:[base length]+1];

            // New Code
            NSString* relPath = [path substringFromIndex:[base length]];
            return relPath;
        }
    }

    NSLog(@"WARNING! ResourceManagerUtil: No relative path");
    return NULL;
}

Replacing the two lines indicated seems to fix the issue for me, and works in brief testing. I'm new to Git, so sorry about not having a pull request. I'm also not sure this change won't introduce other bugs or side-effects.

@vlidholt
Copy link

This needs further investigation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants