CCTextureCache::addImage bug?

Hi,
I found that it seems has a bug with cocos2d-x in CCTextureCache::addImage…
all the pathKey in m_pTextures->setObject(texture, pathKey) should be relative path. (so is cocos2d)
but in cocos2d-x, the pathKey is modified to fullpath at beginning of the if-statement…
This cause CCTextureCache::textureForKey can not get textures load from files.

Thanks for your feedback! There is a bug of method CCTextureCache::textureForKey().
I just created an issue #636 for it.

There are some reason of why use fullpath of image file as the pathKey.
Sometimes the parameter of CCTextureCache::addImage() method is not relative path. Such as in the method CCParticleSystem::initWithDictionary().
So we must use the fullpath as the pathKey.

Hi,
I saw you have done fix this bug in repository.
But I think that the way you fix this bug will cause another bug.
If you add a image/texture with self-defined key, it can not be find by textureForKey / removeTextureForKey
because the key will always be treat as relative path and become a fullpath by using CCFileUtil::fullPathFromRelativePath.
So the key we self-defined will never be found.

Splash Huang wrote:

Hi,
I saw you have done fix this bug in repository.
But I think that the way you fix this bug will cause another bug.
If you add a image/texture with self-defined key, it can not be find by textureForKey / removeTextureForKey
because the key will always be treat as relative path and become a fullpath by using CCFileUtil::fullPathFromRelativePath.
So the key we self-defined will never be found.

Yes, it’s really a problem! I don’t have any good idea for this.
Make sure the parameter of CCTextureCache::addImage() is relative path can resolve this problem!
But by now it’s really difficult to achieve.

Do you have any good idea to resolve this problem?

why not use relative path for the KEY when addImage ?

浩杰 张 wrote:

why not use relative path for the KEY when addImage ?

I know that use relative path for the KEY can resolve the problem! But sometimes we don’t know the relative path of the image file.

Such as the case I described before. In the method CCParticleSystem::initWithDictionary().
The full path of plist file & the image file name is known. It’s too difficult to get the relative path of the image file.
Sorry for that!