issue #1564: Fix crash of ParticlesTest.

This commit is contained in:
James Chen 2012-11-21 17:22:26 +08:00
parent d0ccff9081
commit 3fc2f9888b
1 changed files with 14 additions and 16 deletions

View File

@ -313,31 +313,29 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary, const char *
// texture // texture
// Try to get the texture from the cache // Try to get the texture from the cache
const char* textureName = dictionary->valueForKey("textureFileName")->getCString(); std::string textureName = dictionary->valueForKey("textureFileName")->getCString();
string textureDir = textureName;
if (textureDir.find('/') != string::npos)
{
textureDir = textureDir.substr(0, textureDir.rfind('/') + 1);
}
else
{
textureDir = "";
}
if (textureDir != dirname) size_t rPos = textureName.rfind('/');
if (rPos != string::npos)
{ {
textureName = textureName + textureDir.size(); string textureDir = textureName.substr(0, rPos + 1);
textureName = (string(dirname) + textureName).c_str();
if (dirname != NULL && textureDir != dirname)
{
textureName = textureName.substr(rPos+1);
textureName = string(dirname) + textureName;
}
} }
CCTexture2D *tex = NULL; CCTexture2D *tex = NULL;
if (strlen(textureName) > 0) if (textureName.length() > 0)
{ {
// set not pop-up message box when load image failed // set not pop-up message box when load image failed
bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify(); bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify();
CCFileUtils::sharedFileUtils()->setPopupNotify(false); CCFileUtils::sharedFileUtils()->setPopupNotify(false);
tex = CCTextureCache::sharedTextureCache()->addImage(textureName); tex = CCTextureCache::sharedTextureCache()->addImage(textureName.c_str());
// reset the value of UIImage notify // reset the value of UIImage notify
CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify); CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify);
@ -370,7 +368,7 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary, const char *
CCAssert(isOK, "CCParticleSystem: error init image with Data"); CCAssert(isOK, "CCParticleSystem: error init image with Data");
CC_BREAK_IF(!isOK); CC_BREAK_IF(!isOK);
setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, textureName)); setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, textureName.c_str()));
image->release(); image->release();
} }