Resume after sleep, bug fix proposal


#1

Hi.

I have found a bug, which prevents game applications to resume after sleep, e.g. come to foreground from background. To reproduce the bug you need to start cocos2dx demo and get it on background and try to re-open it again. The result will be an empty white screen or bad looking cocos2dx demo. At least on Android the reason is that the texture cache is not filled properly
with names of texture files, e.g. bitmaps (jpeg, png etc.).

There is a method CCTexture2D * CCTextureCache::addImage(const char * path) in textures\CCTextureCache.cpp file, where texture path names are added to the cache using CCFileUtils::fullPathFromRelativePath(const char pszRelativePath, ccResolutionTypepResolutionType) method from the platform\CCFileUtils.h file. The method is not implemented for other than iOS platform and returns empty string by default.

In case of Android an empty string is cached in texture file name cache causing fail to reload all textures after sleep.

The fix can be made as the following in platform\CCFileUtils.cpp:

/// functions iOS specific
const char* CCFileUtils::fullPathFromRelativePath(const char pszRelativePath, ccResolutionTypepResolutionType)
{
// return “”;
return pszRelativePath; // FIX: otherwise file path will be lost on all other than iOS platforms
}

I think this should fix the bug not only on android, but on other than iOS platforms as well.

BR, Alex


#2

I think it would be more correct for the new line to be as follows, to preserve any intended behavior of fullPathFromRelativePath for other platforms.

return fullPathFromRelativePath(pszRelativePath);


#3

I must be losing my mind. I swear I checked git and it hadn’t been fixed, but in the process of preparing a patch I found out a fix was already submitted.