bug in CCSpriteFrameCache::addSpriteFramesWithFile

bug in CCSpriteFrameCache::addSpriteFramesWithFile
0.0 0


checkout 0.8.5

when my resourcePath is not empty and it is a relative path like “./res/”, it ran error.

void CCSpriteFrameCache::addSpriteFramesWithFile(const char *pszPlist)

at first, set pszPath to so-called FULL path of the .plist file.

<pre>const charpszPath = CCFileUtils::fullPathFromRelativePath(pszPlist);


in followed, textureBase was the so-called FULL path of .plist file.

and then, texture path is relative path from textureBase, so it must be FULL path.

<pre>texturePath = textureBase + “/” + texturePath;</pre>

if resourcePath is ./res, when call the function with “myplist.list”
the above so-called FULL path should be “./res/myplist.list” and “./res/myplist.png”

now, the bug
<pre>CCTexture2DpTexture = CCTextureCache::sharedTextureCache()->addImage(texturePath.c_str());


CCTextureCache::addImage can only use relative path,
the so-called FULL path was be regarded as a relative path,
so app prompt: “./res/./res/myplist.png” cannot found.


Mark. May have problem on win32 & iphone.
I have the phobia of dealing with string :slight_smile: Bin will take this case tomorrow.
A pull request to github repo will be appreciated!


@XuDong Zhai,
I’m sorry that I could’t understand what’s your mean with my resourcePath is not empty and it is a relative path like “./res/”.
How did you set “./res/” into the engine?

By the way, can you simply tell me how to reproduce the probelm? Such like this:
I encounter the problem on XXX platform.
My resource files path is : XXXXXXXXXXXXXXXXXX

Thanks for your feedback! And hope your reply!:slight_smile:


Sample codes of [win32] project ( but not only in [win32] )
see here:

bool AppDelegate::applicationDidFinishLaunching()
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();

    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
    // pDirector->enableRetinaDisplay(true);

    // sets landscape mode

    // turn on display FPS


    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    CCScene *pScene = SceneManager::sceneSandbox();

        const char* paths[] = { "./res/", "../res/" };

        for(int i=0; i

when CCFileUtils::setRelativePath(“./res”)
and then CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(“FILENAME.plist”)
program throw: ./res/./res/FILENAME.png not found (should be ./res/FILENAME.plist )

when CCFileUtils::setRelativePath(“…/res”)
program ran ok, because the PNG filename is …/res/…/res/FILENAME.png equals to …/res/FILENAME.png

i have fix the bug in two lines change,
see also: https://github.com/zhaixudong/cocos2d-x/commit/c676b170a55a4205fea7eea41453a297e9f6885d


I’m sorry that is not a bug of our engine!

First, the parameter of method CCFileUtils::setResourcePath() must be absolute path. You can see this information from the comments in the source:cocos2dx/platform/CCFileUtils.h:

    @brief  Set the ResourcePath,we will find resource in this path
    @param pszResourcePath  The absolute resource path
    static void setResourcePath(const char *pszResourcePath);

Second, the method CCFileUtils::setRelativePath() is only implemented on android. You also can see this information from the comments in the source:cocos2dx/platform/CCFileUtils.h:

    // interfaces on android
    static const char* getResourcePath(void);
    static void setRelativePath(const char* pszRelativePath);

Strongly recommend that, if you are not really understand the implemention of resource-reading on android, don’t invoke this function yourself.

Anyway, thanks for your feedback. Hope it’s helpful and best wishes to you!


sorry, i means CCFileUtils::setResourcePath(“./res”), i typed wrong upon.

the function setResourcePath CAN be use in windows and it’s important for windows version.
however android or win32, this is a bug.

ok, the function can only support absolute resource path. ( in fact, it should can changed to support )

no mind, i made correctly this problem for my app.

thanks for your feedback, :slight_smile: