mirror of https://github.com/axmolengine/axmol.git
[Mac] fix CC_ASSERT error
[Mac] add CC_DISABLE_ASSERT check [cocos2d-x] CCSprite::createWithSpriteFrame() check pSpriteFrame
This commit is contained in:
parent
dcc8733a53
commit
39b019b2cb
|
@ -36,13 +36,13 @@ CCApplication* CCApplication::sm_pSharedApplication = 0;
|
||||||
|
|
||||||
CCApplication::CCApplication()
|
CCApplication::CCApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(! sm_pSharedApplication);
|
CCAssert(! sm_pSharedApplication, "sm_pSharedApplication already exist");
|
||||||
sm_pSharedApplication = this;
|
sm_pSharedApplication = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCApplication::~CCApplication()
|
CCApplication::~CCApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(this == sm_pSharedApplication);
|
CCAssert(this == sm_pSharedApplication, "sm_pSharedApplication != this");
|
||||||
sm_pSharedApplication = 0;
|
sm_pSharedApplication = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ TargetPlatform CCApplication::getTargetPlatform()
|
||||||
|
|
||||||
CCApplication* CCApplication::sharedApplication()
|
CCApplication* CCApplication::sharedApplication()
|
||||||
{
|
{
|
||||||
CC_ASSERT(sm_pSharedApplication);
|
CCAssert(sm_pSharedApplication, "sm_pSharedApplication not set");
|
||||||
return sm_pSharedApplication;
|
return sm_pSharedApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2010-2011 cocos2d-x.org
|
Copyright (c) 2010-2011 cocos2d-x.org
|
||||||
Copyright (c) 2011 Zynga Inc.
|
Copyright (c) 2011 Zynga Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
in the Software without restriction, including without limitation the rights
|
in the Software without restriction, including without limitation the rights
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
furnished to do so, subject to the following conditions:
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
The above copyright notice and this permission notice shall be included in
|
||||||
all copies or substantial portions of the Software.
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -56,7 +56,7 @@ static void static_addItemToCCArray(id item, CCArray *pArray)
|
||||||
pValue->release();
|
pValue->release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add number value into array(such as int, float, bool and so on)
|
// add number value into array(such as int, float, bool and so on)
|
||||||
if ([item isKindOfClass:[NSNumber class]]) {
|
if ([item isKindOfClass:[NSNumber class]]) {
|
||||||
NSString* pStr = [item stringValue];
|
NSString* pStr = [item stringValue];
|
||||||
|
@ -97,7 +97,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
|
||||||
// the key must be a string
|
// the key must be a string
|
||||||
CCAssert([key isKindOfClass:[NSString class]], "The key should be a string!");
|
CCAssert([key isKindOfClass:[NSString class]], "The key should be a string!");
|
||||||
std::string pKey = [key UTF8String];
|
std::string pKey = [key UTF8String];
|
||||||
|
|
||||||
// the value is a new dictionary
|
// the value is a new dictionary
|
||||||
if ([value isKindOfClass:[NSDictionary class]]) {
|
if ([value isKindOfClass:[NSDictionary class]]) {
|
||||||
CCDictionary* pSubDict = new CCDictionary();
|
CCDictionary* pSubDict = new CCDictionary();
|
||||||
|
@ -109,16 +109,16 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
|
||||||
pSubDict->release();
|
pSubDict->release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the value is a string
|
// the value is a string
|
||||||
if ([value isKindOfClass:[NSString class]]) {
|
if ([value isKindOfClass:[NSString class]]) {
|
||||||
CCString* pValue = new CCString([value UTF8String]);
|
CCString* pValue = new CCString([value UTF8String]);
|
||||||
|
|
||||||
pDict->setObject(pValue, pKey.c_str());
|
pDict->setObject(pValue, pKey.c_str());
|
||||||
pValue->release();
|
pValue->release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the value is a number
|
// the value is a number
|
||||||
if ([value isKindOfClass:[NSNumber class]]) {
|
if ([value isKindOfClass:[NSNumber class]]) {
|
||||||
NSString* pStr = [value stringValue];
|
NSString* pStr = [value stringValue];
|
||||||
|
@ -128,7 +128,7 @@ static void static_addValueToCCDict(id key, id value, CCDictionary* pDict)
|
||||||
pValue->release();
|
pValue->release();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the value is a array
|
// the value is a array
|
||||||
if ([value isKindOfClass:[NSArray class]]) {
|
if ([value isKindOfClass:[NSArray class]]) {
|
||||||
CCArray *pArray = new CCArray();
|
CCArray *pArray = new CCArray();
|
||||||
|
@ -164,13 +164,13 @@ void CCFileUtils::purgeFileUtils()
|
||||||
{
|
{
|
||||||
s_pFileUtils->purgeCachedEntries();
|
s_pFileUtils->purgeCachedEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_SAFE_DELETE(s_pFileUtils);
|
CC_SAFE_DELETE(s_pFileUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCFileUtils::purgeCachedEntries()
|
void CCFileUtils::purgeCachedEntries()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCFileUtils::setResourceDirectory(const char *pszDirectoryName, bool isWorkingDir)
|
void CCFileUtils::setResourceDirectory(const char *pszDirectoryName, bool isWorkingDir)
|
||||||
|
@ -264,7 +264,7 @@ CCArray* ccFileUtils_arrayWithContentsOfFileThreadSafe(const char* pFileName)
|
||||||
for (id value in pArray) {
|
for (id value in pArray) {
|
||||||
static_addItemToCCArray(value, pRet);
|
static_addItemToCCArray(value, pRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,12 +273,12 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
unsigned char * pBuffer = NULL;
|
unsigned char * pBuffer = NULL;
|
||||||
CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invaild parameters.");
|
CCAssert(pszFileName != NULL && pSize != NULL && pszMode != NULL, "Invaild parameters.");
|
||||||
*pSize = 0;
|
*pSize = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// read the file from hardware
|
// read the file from hardware
|
||||||
FILE *fp = fopen(pszFileName, pszMode);
|
FILE *fp = fopen(pszFileName, pszMode);
|
||||||
CC_BREAK_IF(!fp);
|
CC_BREAK_IF(!fp);
|
||||||
|
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
*pSize = ftell(fp);
|
*pSize = ftell(fp);
|
||||||
fseek(fp,0,SEEK_SET);
|
fseek(fp,0,SEEK_SET);
|
||||||
|
@ -286,13 +286,13 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
||||||
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
*pSize = fread(pBuffer,sizeof(unsigned char), *pSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (! pBuffer && isPopupNotify())
|
if (! pBuffer && isPopupNotify())
|
||||||
{
|
{
|
||||||
std::string title = "Notification";
|
std::string title = "Notification";
|
||||||
std::string msg = "Get data from file(";
|
std::string msg = "Get data from file(";
|
||||||
msg.append(pszFileName).append(") failed!");
|
msg.append(pszFileName).append(") failed!");
|
||||||
|
|
||||||
CCMessageBox(msg.c_str(), title.c_str());
|
CCMessageBox(msg.c_str(), title.c_str());
|
||||||
}
|
}
|
||||||
return pBuffer;
|
return pBuffer;
|
||||||
|
@ -323,44 +323,44 @@ std::string CCFileUtils::getWriteablePath()
|
||||||
|
|
||||||
unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
|
unsigned char* CCFileUtils::getFileDataFromZip(const char* pszZipFilePath, const char* pszFileName, unsigned long * pSize)
|
||||||
{
|
{
|
||||||
unsigned char * pBuffer = NULL;
|
unsigned char * pBuffer = NULL;
|
||||||
unzFile pFile = NULL;
|
unzFile pFile = NULL;
|
||||||
*pSize = 0;
|
*pSize = 0;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
CC_BREAK_IF(!pszZipFilePath || !pszFileName);
|
CC_BREAK_IF(!pszZipFilePath || !pszFileName);
|
||||||
CC_BREAK_IF(strlen(pszZipFilePath) == 0);
|
CC_BREAK_IF(strlen(pszZipFilePath) == 0);
|
||||||
|
|
||||||
|
pFile = unzOpen(pszZipFilePath);
|
||||||
|
CC_BREAK_IF(!pFile);
|
||||||
|
|
||||||
|
int nRet = unzLocateFile(pFile, pszFileName, 1);
|
||||||
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
|
char szFilePathA[260];
|
||||||
|
unz_file_info FileInfo;
|
||||||
|
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
|
||||||
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
|
nRet = unzOpenCurrentFile(pFile);
|
||||||
|
CC_BREAK_IF(UNZ_OK != nRet);
|
||||||
|
|
||||||
|
pBuffer = new unsigned char[FileInfo.uncompressed_size];
|
||||||
|
int nSize = 0;
|
||||||
|
nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
|
||||||
|
CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
|
||||||
|
|
||||||
|
*pSize = FileInfo.uncompressed_size;
|
||||||
|
unzCloseCurrentFile(pFile);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
pFile = unzOpen(pszZipFilePath);
|
if (pFile)
|
||||||
CC_BREAK_IF(!pFile);
|
{
|
||||||
|
unzClose(pFile);
|
||||||
|
}
|
||||||
|
|
||||||
int nRet = unzLocateFile(pFile, pszFileName, 1);
|
return pBuffer;
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
|
||||||
|
|
||||||
char szFilePathA[260];
|
|
||||||
unz_file_info FileInfo;
|
|
||||||
nRet = unzGetCurrentFileInfo(pFile, &FileInfo, szFilePathA, sizeof(szFilePathA), NULL, 0, NULL, 0);
|
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
|
||||||
|
|
||||||
nRet = unzOpenCurrentFile(pFile);
|
|
||||||
CC_BREAK_IF(UNZ_OK != nRet);
|
|
||||||
|
|
||||||
pBuffer = new unsigned char[FileInfo.uncompressed_size];
|
|
||||||
int nSize = 0;
|
|
||||||
nSize = unzReadCurrentFile(pFile, pBuffer, FileInfo.uncompressed_size);
|
|
||||||
CCAssert(nSize == 0 || nSize == (int)FileInfo.uncompressed_size, "the file size is wrong");
|
|
||||||
|
|
||||||
*pSize = FileInfo.uncompressed_size;
|
|
||||||
unzCloseCurrentFile(pFile);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
if (pFile)
|
|
||||||
{
|
|
||||||
unzClose(pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -340,8 +340,8 @@ static bool _initWithString(const char * pText, cocos2d::CCImage::ETextAlign eAl
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
|
|
||||||
CCAssert( pText, @"Invalid pText");
|
CCAssert(pText, "Invalid pText");
|
||||||
CCAssert( pInfo, @"Invalid pInfo");
|
CCAssert(pInfo, "Invalid pInfo");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
NSString * string = [NSString stringWithUTF8String:pText];
|
NSString * string = [NSString stringWithUTF8String:pText];
|
||||||
|
|
|
@ -5,8 +5,11 @@
|
||||||
|
|
||||||
#define CC_DLL
|
#define CC_DLL
|
||||||
|
|
||||||
|
#if CC_DISABLE_ASSERT > 0
|
||||||
|
#define CC_ASSERT(cond)
|
||||||
|
#else
|
||||||
#define CC_ASSERT(cond) assert(cond)
|
#define CC_ASSERT(cond) assert(cond)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam
|
#define CC_UNUSED_PARAM(unusedparam) (void)unusedparam
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ CCSprite* CCSprite::spriteWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
|
||||||
CCSprite* CCSprite::createWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
|
CCSprite* CCSprite::createWithSpriteFrame(CCSpriteFrame *pSpriteFrame)
|
||||||
{
|
{
|
||||||
CCSprite *pobSprite = new CCSprite();
|
CCSprite *pobSprite = new CCSprite();
|
||||||
if (pobSprite && pobSprite->initWithSpriteFrame(pSpriteFrame))
|
if (pSpriteFrame && pobSprite && pobSprite->initWithSpriteFrame(pSpriteFrame))
|
||||||
{
|
{
|
||||||
pobSprite->autorelease();
|
pobSprite->autorelease();
|
||||||
return pobSprite;
|
return pobSprite;
|
||||||
|
@ -152,10 +152,13 @@ CCSprite* CCSprite::spriteWithSpriteFrameName(const char *pszSpriteFrameName)
|
||||||
CCSprite* CCSprite::createWithSpriteFrameName(const char *pszSpriteFrameName)
|
CCSprite* CCSprite::createWithSpriteFrameName(const char *pszSpriteFrameName)
|
||||||
{
|
{
|
||||||
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);
|
CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG > 0
|
||||||
char msg[256] = {0};
|
char msg[256] = {0};
|
||||||
sprintf(msg, "Invalid spriteFrameName: %s", pszSpriteFrameName);
|
sprintf(msg, "Invalid spriteFrameName: %s", pszSpriteFrameName);
|
||||||
CCAssert(pFrame != NULL, msg);
|
CCAssert(pFrame != NULL, msg);
|
||||||
|
#endif
|
||||||
|
|
||||||
return createWithSpriteFrame(pFrame);
|
return createWithSpriteFrame(pFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ int CCLuaEngine::executeString(const char *codes)
|
||||||
int CCLuaEngine::executeScriptFile(const char* filename)
|
int CCLuaEngine::executeScriptFile(const char* filename)
|
||||||
{
|
{
|
||||||
int nRet = luaL_dofile(m_state, filename);
|
int nRet = luaL_dofile(m_state, filename);
|
||||||
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
||||||
|
|
||||||
if (nRet != 0)
|
if (nRet != 0)
|
||||||
{
|
{
|
||||||
|
@ -115,7 +115,7 @@ int CCLuaEngine::executeScriptFile(const char* filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCLuaEngine::executeGlobalFunction(const char* functionName)
|
int CCLuaEngine::executeGlobalFunction(const char* functionName)
|
||||||
{
|
{
|
||||||
lua_getglobal(m_state, functionName); /* query function by name, stack: function */
|
lua_getglobal(m_state, functionName); /* query function by name, stack: function */
|
||||||
if (!lua_isfunction(m_state, -1))
|
if (!lua_isfunction(m_state, -1))
|
||||||
|
@ -126,7 +126,7 @@ int CCLuaEngine::executeGlobalFunction(const char* functionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
int error = lua_pcall(m_state, 0, 1, 0); /* call function, stack: ret */
|
int error = lua_pcall(m_state, 0, 1, 0); /* call function, stack: ret */
|
||||||
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
// lua_gc(m_state, LUA_GCCOLLECT, 0);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue