diff --git a/cocos2dx/CCConfiguration.cpp b/cocos2dx/CCConfiguration.cpp index 109758ff8f..7b4b326483 100644 --- a/cocos2dx/CCConfiguration.cpp +++ b/cocos2dx/CCConfiguration.cpp @@ -37,7 +37,7 @@ CCConfiguration::CCConfiguration(void) { } -CCConfiguration* CCConfiguration::init(void) +bool CCConfiguration::init(void) { CCLOG("cocos2d: GL_VENDOR: %s", glGetString(GL_VENDOR)); CCLOG("cocos2d: GL_RENDERER: %s", glGetString(GL_RENDERER)); @@ -73,7 +73,7 @@ CCConfiguration* CCConfiguration::init(void) CCLOG("cocos2d: compiled with VBO support in TextureAtlas : %s", "NO"); #endif // CC_TEXTURE_ATLAS_USES_VBO - return this; + return true; } diff --git a/cocos2dx/CCConfiguration.h b/cocos2dx/CCConfiguration.h index df311500c6..f81526a91e 100644 --- a/cocos2dx/CCConfiguration.h +++ b/cocos2dx/CCConfiguration.h @@ -96,7 +96,7 @@ public: // returns whether or not an OpenGL is supported bool checkForGLExtension(const std::string &searchName); - CCConfiguration* init(void); + bool init(void); public: // returns a shared instance of the CCConfiguration diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index ff23106b16..5e4f7d9d72 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -100,7 +100,7 @@ bool CCDirector::setDierectorType(ccDirectorType obDirectorType) return true; } -CCDirector* CCDirector::init(void) +bool CCDirector::init(void) { CCLOG("cocos2d: %s", cocos2dVersion()); @@ -138,7 +138,7 @@ CCDirector* CCDirector::init(void) // create autorelease pool NSPoolManager::getInstance()->push(); - return this; + return true; } CCDirector::~CCDirector(void) diff --git a/cocos2dx/actions/CCAction.cpp b/cocos2dx/actions/CCAction.cpp index 489279cb5e..e6237d1b99 100644 --- a/cocos2dx/actions/CCAction.cpp +++ b/cocos2dx/actions/CCAction.cpp @@ -132,12 +132,13 @@ CCSpeed * CCSpeed::actionWithAction(CCIntervalAction *pAction, float fRate) return NULL; } -CCSpeed * CCSpeed::initWithAction(CCIntervalAction *pAction, float fRate) +bool CCSpeed::initWithAction(CCIntervalAction *pAction, float fRate) { + assert(pAction != NULL); pAction->retain(); m_pOther = pAction; m_fSpeed = fRate; - return this; + return true; } NSObject *CCSpeed::copyWithZone(NSZone *pZone) @@ -219,8 +220,9 @@ CCFollow *CCFollow::actionWithTarget(CCNode *pFollowedNode, CGRect rect) return NULL; } -CCFollow *CCFollow::initWithTarget(CCNode *pFollowedNode) +bool CCFollow::initWithTarget(CCNode *pFollowedNode) { + assert(pFollowedNode != NULL); pFollowedNode->retain(); m_pobFollowedNode = pFollowedNode; m_bBoundarySet = false; @@ -229,11 +231,12 @@ CCFollow *CCFollow::initWithTarget(CCNode *pFollowedNode) CGSize winSize = CCDirector::getSharedDirector()->getWinSize(); m_obFullScreenSize = CGPointMake(winSize.width, winSize.height); m_obHalfScreenSize = ccpMult(m_obFullScreenSize, 0.5f); - return this; + return true; } -CCFollow *CCFollow::initWithTarget(CCNode *pFollowedNode, CGRect rect) +bool CCFollow::initWithTarget(CCNode *pFollowedNode, CGRect rect) { + assert(pFollowedNode != NULL); pFollowedNode->retain(); m_pobFollowedNode = pFollowedNode; m_bBoundarySet = true; @@ -265,7 +268,7 @@ CCFollow *CCFollow::initWithTarget(CCNode *pFollowedNode, CGRect rect) { m_bBoundaryFullyCovered = true; } - return this; + return true; } NSObject *CCFollow::copyWithZone(NSZone *pZone) { diff --git a/cocos2dx/actions/CCActionManager.cpp b/cocos2dx/actions/CCActionManager.cpp index 2dff99a326..3317fddd36 100644 --- a/cocos2dx/actions/CCActionManager.cpp +++ b/cocos2dx/actions/CCActionManager.cpp @@ -97,12 +97,12 @@ CCActionManager::~CCActionManager(void) gSharedManager = NULL; } -CCActionManager* CCActionManager::init(void) +bool CCActionManager::init(void) { CCScheduler::getSharedScheduler()->scheduleUpdateForTarget(this, 0, false); m_pTargets = NULL; - return this; + return true; } // private diff --git a/cocos2dx/actions/CCCameraAction.cpp b/cocos2dx/actions/CCCameraAction.cpp index 2c40dbd777..7fbc6f8eaf 100644 --- a/cocos2dx/actions/CCCameraAction.cpp +++ b/cocos2dx/actions/CCCameraAction.cpp @@ -50,9 +50,13 @@ namespace cocos2d{ CCOrbitCamera * CCOrbitCamera::actionWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX) { CCOrbitCamera * pRet = new CCOrbitCamera(); - pRet->initWithDuration(t, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX); - pRet->autorelease(); - return pRet; + if(pRet->initWithDuration(t, radius, deltaRadius, angleZ, deltaAngleZ, angleX, deltaAngleX)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } NSObject * CCOrbitCamera::copyWithZone(NSZone *pZone) @@ -75,7 +79,7 @@ namespace cocos2d{ return pRet; } - CCOrbitCamera * CCOrbitCamera::initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX) + bool CCOrbitCamera::initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX) { if ( CCIntervalAction::initWithDuration(t) ) { @@ -88,9 +92,9 @@ namespace cocos2d{ m_fRadDeltaZ = (CGFloat)CC_DEGREES_TO_RADIANS(deltaAngleZ); m_fRadDeltaX = (CGFloat)CC_DEGREES_TO_RADIANS(deltaAngleX); - return this; + return true; } - return NULL; + return false; } void CCOrbitCamera::startWithTarget(CCNode *pTarget) diff --git a/cocos2dx/actions/CCInstantAction.cpp b/cocos2dx/actions/CCInstantAction.cpp index 3fbfbaa39b..1f9aa49988 100644 --- a/cocos2dx/actions/CCInstantAction.cpp +++ b/cocos2dx/actions/CCInstantAction.cpp @@ -131,10 +131,10 @@ namespace cocos2d { pRet->autorelease(); return pRet; } - CCFlipX *CCFlipX::initWithFlipX(bool x) + bool CCFlipX::initWithFlipX(bool x) { m_bFlipX = x; - return this; + return true; } void CCFlipX::startWithTarget(CCNode *pTarget) { @@ -176,10 +176,10 @@ namespace cocos2d { pRet->autorelease(); return pRet; } - CCFlipY * CCFlipY::initWithFlipY(bool y) + bool CCFlipY::initWithFlipY(bool y) { m_bFlipY = y; - return this; + return true; } void CCFlipY::startWithTarget(CCNode *pTarget) @@ -222,10 +222,10 @@ namespace cocos2d { pRet->autorelease(); return pRet; } - CCPlace * CCPlace::initWithPosition(CGPoint pos) + bool CCPlace::initWithPosition(CGPoint pos) { m_tPosition = pos; - return this; + return true; } NSObject * CCPlace::copyWithZone(NSZone *pZone) @@ -267,10 +267,10 @@ namespace cocos2d { return pCallFunc; } - CCCallFunc * CCCallFunc::initWithTarget(SelectorProtocol* pSelectorTarget) + bool CCCallFunc::initWithTarget(SelectorProtocol* pSelectorTarget) { m_pSelectorTarget = pSelectorTarget; - return this; + return true; } NSObject * CCCallFunc::copyWithZone(cocos2d::NSZone *pZone) @@ -327,19 +327,24 @@ namespace cocos2d { CCCallFuncND * CCCallFuncND::actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d) { CCCallFuncND* pRet = new CCCallFuncND(); - pRet->initWithTarget(pSelectorTarget, selector, d); - pRet->autorelease(); - return pRet; + if (pRet->initWithTarget(pSelectorTarget, selector, d)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } - CCCallFuncND * CCCallFuncND::initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d) + bool CCCallFuncND::initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d) { if( CCCallFunc::initWithTarget(pSelectorTarget) ) { m_pData = d; m_pCallFuncND = selector; + return true; } - return this; + return false; } NSObject * CCCallFuncND::copyWithZone(NSZone* zone) diff --git a/cocos2dx/actions/CCIntervalAction.cpp b/cocos2dx/actions/CCIntervalAction.cpp index d3475b9616..9a27eb1c19 100644 --- a/cocos2dx/actions/CCIntervalAction.cpp +++ b/cocos2dx/actions/CCIntervalAction.cpp @@ -442,11 +442,12 @@ CCRepeatForever *CCRepeatForever::actionWithAction(CCIntervalAction *pAction) return NULL; } -CCRepeatForever *CCRepeatForever::initWithAction(CCIntervalAction *pAction) +bool CCRepeatForever::initWithAction(CCIntervalAction *pAction) { + assert(pAction != NULL); pAction->retain(); m_pOther = pAction; - return this; + return true; } NSObject* CCRepeatForever::copyWithZone(NSZone *pZone) { diff --git a/cocos2dx/base_nodes/CCAtlasNode.cpp b/cocos2dx/base_nodes/CCAtlasNode.cpp index 70e1425e90..81c6bb91c4 100644 --- a/cocos2dx/base_nodes/CCAtlasNode.cpp +++ b/cocos2dx/base_nodes/CCAtlasNode.cpp @@ -42,15 +42,19 @@ CCAtlasNode::~CCAtlasNode() CCAtlasNode * CCAtlasNode::atlasWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender) { - CCAtlasNode * pAtlasNode = new CCAtlasNode(); - pAtlasNode->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender); - pAtlasNode->autorelease(); - return pAtlasNode; + CCAtlasNode * pRet = new CCAtlasNode(); + if (pRet->initWithTileFile(tile, tileWidth, tileHeight, itemsToRender)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } -CCAtlasNode * CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender) +bool CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender) { - + assert(tile != NULL); m_nItemWidth = tileWidth; m_nItemHeight = tileHeight; @@ -73,7 +77,7 @@ CCAtlasNode * CCAtlasNode::initWithTileFile(const char *tile, int tileWidth, int this->calculateMaxItems(); this->calculateTexCoordsSteps(); - return this; + return true; } diff --git a/cocos2dx/include/CCAction.h b/cocos2dx/include/CCAction.h index 6dc216de08..823247d34f 100644 --- a/cocos2dx/include/CCAction.h +++ b/cocos2dx/include/CCAction.h @@ -136,7 +136,7 @@ public: void setSpeed(float fSpeed) { m_fSpeed = fSpeed; } // initializes the action - CCSpeed* initWithAction(CCIntervalAction *pAction, float fRate); + bool initWithAction(CCIntervalAction *pAction, float fRate); /* CCSpeed* initWithAction(CCRepeatForever *pAction, float fRate);*/ virtual NSObject* copyWithZone(NSZone *pZone); @@ -180,10 +180,10 @@ public: void setBoudarySet(bool bValue) { m_bBoundarySet = bValue; } // initializes the action - CCFollow* initWithTarget(CCNode *pFollowedNode); + bool initWithTarget(CCNode *pFollowedNode); // initializes the action with a set boundary - CCFollow* initWithTarget(CCNode *pFollowedNode, CGRect rect); + bool initWithTarget(CCNode *pFollowedNode, CGRect rect); virtual NSObject* copyWithZone(NSZone *pZone); virtual void step(ccTime dt); diff --git a/cocos2dx/include/CCActionManager.h b/cocos2dx/include/CCActionManager.h index 126229bc13..0d60034275 100644 --- a/cocos2dx/include/CCActionManager.h +++ b/cocos2dx/include/CCActionManager.h @@ -49,7 +49,7 @@ class CCX_DLL CCActionManager : public NSObject, public SelectorProtocol public: CCActionManager(void); ~CCActionManager(void); - CCActionManager* init(void); + bool init(void); // actions diff --git a/cocos2dx/include/CCAtlasNode.h b/cocos2dx/include/CCAtlasNode.h index 592e7a8ccd..3ad93f4f29 100644 --- a/cocos2dx/include/CCAtlasNode.h +++ b/cocos2dx/include/CCAtlasNode.h @@ -78,7 +78,7 @@ public: static CCAtlasNode * atlasWithTileFile(const char* tile,int tileWidth, int tileHeight, int itemsToRender); /** initializes an CCAtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ - CCAtlasNode * initWithTileFile(const char* tile, int tileWidth, int tileHeight, int itemsToRender); + bool initWithTileFile(const char* tile, int tileWidth, int tileHeight, int itemsToRender); /** updates the Atlas (indexed vertex array). * Shall be overriden in subclasses diff --git a/cocos2dx/include/CCBitmapFontAtlas.h b/cocos2dx/include/CCBitmapFontAtlas.h index 4d331ce400..541daa8e05 100644 --- a/cocos2dx/include/CCBitmapFontAtlas.h +++ b/cocos2dx/include/CCBitmapFontAtlas.h @@ -90,7 +90,7 @@ namespace cocos2d{ /** allocates a CCBitmapFontConfiguration with a FNT file */ static CCBitmapFontConfiguration * configurationWithFNTFile(const char *FNTfile); /** initializes a BitmapFontConfiguration with a FNT file */ - CCBitmapFontConfiguration * initWithFNTfile(const char *FNTfile); + bool initWithFNTfile(const char *FNTfile); private: void parseConfigFile(const char *controlFile); void parseCharacterDefinition(std::string line, ccBitmapFontDef *characterDefinition); @@ -156,7 +156,7 @@ namespace cocos2d{ /** creates a bitmap font altas with an initial string and the FNT file */ static CCBitmapFontAtlas * bitmapFontAtlasWithString(const char *str, const char *fntFile); /** init a bitmap font altas with an initial string and the FNT file */ - CCBitmapFontAtlas * initWithString(const char *str, const char *fntFile); + bool initWithString(const char *str, const char *fntFile); /** updates the font chars based on the string to render */ void createFontChars(); // super method diff --git a/cocos2dx/include/CCCameraAction.h b/cocos2dx/include/CCCameraAction.h index 80a6682ac9..a51b6448da 100644 --- a/cocos2dx/include/CCCameraAction.h +++ b/cocos2dx/include/CCCameraAction.h @@ -74,7 +74,7 @@ namespace cocos2d { /** creates a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ static CCOrbitCamera * actionWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX); /** initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */ - CCOrbitCamera * initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX); + bool initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX); /** positions the camera according to spherical coordinates */ void sphericalRadius(float *r, float *zenith, float *azimuth); // super methods diff --git a/cocos2dx/include/CCDirector.h b/cocos2dx/include/CCDirector.h index 66724729a3..b7c57c4149 100644 --- a/cocos2dx/include/CCDirector.h +++ b/cocos2dx/include/CCDirector.h @@ -198,7 +198,7 @@ and when to execute the Scenes. class CCX_DLL CCDirector : public NSObject { public: - virtual CCDirector* init(void); + virtual bool init(void); virtual ~CCDirector(void); CCDirector(void) {} diff --git a/cocos2dx/include/CCInstantAction.h b/cocos2dx/include/CCInstantAction.h index 58923ea446..d20dd552c5 100644 --- a/cocos2dx/include/CCInstantAction.h +++ b/cocos2dx/include/CCInstantAction.h @@ -102,7 +102,7 @@ namespace cocos2d { virtual ~CCFlipX(){} static CCFlipX * actionWithFlipX(bool x); - CCFlipX * initWithFlipX(bool x); + bool initWithFlipX(bool x); //super method virtual void startWithTarget(CCNode *pTarget); virtual CCFiniteTimeAction * reverse(void); @@ -122,7 +122,7 @@ namespace cocos2d { virtual ~CCFlipY(){} static CCFlipY * actionWithFlipY(bool y); - CCFlipY * initWithFlipY(bool y); + bool initWithFlipY(bool y); //super method virtual void startWithTarget(CCNode *pTarget); virtual CCFiniteTimeAction * reverse(void); @@ -142,7 +142,7 @@ namespace cocos2d { /** creates a Place action with a position */ static CCPlace * actionWithPosition(CGPoint pos); /** Initializes a Place action with a position */ - CCPlace * initWithPosition(CGPoint pos); + bool initWithPosition(CGPoint pos); //super method virtual void startWithTarget(CCNode *pTarget); virtual NSObject* copyWithZone(NSZone *pZone); @@ -164,7 +164,7 @@ namespace cocos2d { { } static CCCallFunc * actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFunc selector); - virtual CCCallFunc * initWithTarget(SelectorProtocol* pSelectorTarget); + virtual bool initWithTarget(SelectorProtocol* pSelectorTarget); virtual void execute(); //super method virtual void startWithTarget(CCNode *pTarget); @@ -216,7 +216,7 @@ namespace cocos2d { /** creates the action with the callback and the data to pass as an argument */ static CCCallFuncND * actionWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d); /** initializes the action with the callback and the data to pass as an argument */ - CCCallFuncND * initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d); + virtual bool initWithTarget(SelectorProtocol* pSelectorTarget, SEL_CallFuncND selector, void* d); // super method virtual NSObject* copyWithZone(NSZone *pZone); virtual void execute(); diff --git a/cocos2dx/include/CCIntervalAction.h b/cocos2dx/include/CCIntervalAction.h index 88354f97f5..5d1cc54eda 100644 --- a/cocos2dx/include/CCIntervalAction.h +++ b/cocos2dx/include/CCIntervalAction.h @@ -148,7 +148,7 @@ public: CCRepeatForever(){} virtual ~CCRepeatForever(); - CCRepeatForever* initWithAction(CCIntervalAction *pAction); + bool initWithAction(CCIntervalAction *pAction); virtual NSObject* copyWithZone(NSZone *pZone); virtual void startWithTarget(CCNode* pTarget); virtual void step(ccTime dt); diff --git a/cocos2dx/include/CCLabel.h b/cocos2dx/include/CCLabel.h index d7949dc6a2..5f3953937e 100644 --- a/cocos2dx/include/CCLabel.h +++ b/cocos2dx/include/CCLabel.h @@ -47,9 +47,9 @@ namespace cocos2d{ /** creates a CCLabel from a fontname and font size */ static CCLabel * labelWithString(const char *label, const char *fontName, float fontSize); /** initializes the CCLabel with a font name, alignment, dimension and font size */ - CCLabel * initWithString(const char *label, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize); + bool initWithString(const char *label, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize); /** initializes the CCLabel with a font name and font size */ - CCLabel * initWithString(const char *label, const char *fontName, float fontSize); + bool initWithString(const char *label, const char *fontName, float fontSize); /** changes the string to render * @warning Changing the string is as expensive as creating a new CCLabel. To obtain better performance use CCLabelAtlas diff --git a/cocos2dx/include/CCLabelAtlas.h b/cocos2dx/include/CCLabelAtlas.h index 9329a949b0..fa9ed5ce16 100644 --- a/cocos2dx/include/CCLabelAtlas.h +++ b/cocos2dx/include/CCLabelAtlas.h @@ -51,7 +51,7 @@ namespace cocos2d{ static CCLabelAtlas * labelAtlasWithString(const char *label, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap); /** initializes the CCLabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas */ - CCLabelAtlas * initWithString(const char *label, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap); + bool initWithString(const char *label, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap); // super methods virtual void updateAtlasValues(); virtual void setString(const char *label); diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index 891652671c..251d437d25 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -110,9 +110,9 @@ public: static CCColorLayer * layerWithColor(ccColor4B color); /** initializes a CCLayer with color, width and height */ - CCColorLayer * initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height); + bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height); /** initializes a CCLayer with color. Width and height are the window size. */ - CCColorLayer * initWithColor(ccColor4B color); + bool initWithColor(ccColor4B color); /** change width */ void changeWidth(GLfloat w); @@ -154,7 +154,7 @@ public: /** creates a CCMultiplexLayer with one or more layers using a variable argument list. */ static CCMultiplexLayer * layerWithLayers(CCLayer* layer, ... ); /** initializes a MultiplexLayer with one or more layers using a variable argument list. */ - CCMultiplexLayer * initWithLayers(CCLayer* layer, va_list params); + bool initWithLayers(CCLayer* layer, va_list params); /** switches to a certain layer indexed by n. The current (old) layer will be removed from it's parent with 'cleanup:YES'. */ diff --git a/cocos2dx/include/CCMenu.h b/cocos2dx/include/CCMenu.h index 410621d92c..3105dc5979 100644 --- a/cocos2dx/include/CCMenu.h +++ b/cocos2dx/include/CCMenu.h @@ -50,7 +50,7 @@ namespace cocos2d{ static CCMenu* menuWithItems(CCMenuItem* item, ...); /** initializes a CCMenu with it's items */ - CCMenu * initWithItems(CCMenuItem* item, va_list args); + bool initWithItems(CCMenuItem* item, va_list args); /** align items vertically */ void alignItemsVertically(); diff --git a/cocos2dx/include/CCMenuItem.h b/cocos2dx/include/CCMenuItem.h index e641d9f50a..466dcad235 100644 --- a/cocos2dx/include/CCMenuItem.h +++ b/cocos2dx/include/CCMenuItem.h @@ -56,7 +56,7 @@ namespace cocos2d{ /** Creates a CCMenuItem with a target/selector */ static CCMenuItem * itemWithTarget(SelectorProtocol *rec, SEL_MunuHandler selector); /** Initializes a CCMenuItem with a target/selector */ - CCMenuItem * initWithTarget(SelectorProtocol *rec, SEL_MunuHandler selector); + bool initWithTarget(SelectorProtocol *rec, SEL_MunuHandler selector); /** Returns the outside box */ CGRect rect(); /** Activate the item */ @@ -91,7 +91,7 @@ namespace cocos2d{ /** creates a CCMenuItemLabel with a Label, target and selector */ static CCMenuItemLabel * itemWithLabel(CCNode*label, SelectorProtocol* target, SEL_MunuHandler selector); /** initializes a CCMenuItemLabel with a Label, target and selector */ - CCMenuItemLabel * initWithLabel(CCNode* label, SelectorProtocol* target, SEL_MunuHandler selector); + bool initWithLabel(CCNode* label, SelectorProtocol* target, SEL_MunuHandler selector); /** sets a new string to the inner label */ void setString(const char * label); // super methods @@ -127,7 +127,7 @@ namespace cocos2d{ /** creates a menu item from a string and atlas. Use it with MenuItemToggle */ static CCMenuItemAtlasFont* itemFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol* target, SEL_MunuHandler selector); /** initializes a menu item from a string and atlas with a target/selector */ - CCMenuItemAtlasFont* initFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol* target, SEL_MunuHandler selector); + bool initFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol* target, SEL_MunuHandler selector); }; /** A CCMenuItemFont @@ -151,7 +151,7 @@ namespace cocos2d{ /** creates a menu item from a string with a target/selector */ static CCMenuItemFont * itemFromString(const char *value, SelectorProtocol* target, SEL_MunuHandler selector); /** initializes a menu item from a string with a target/selector */ - CCMenuItemFont * initFromString(const char *value, SelectorProtocol* target, SEL_MunuHandler selector); + bool initFromString(const char *value, SelectorProtocol* target, SEL_MunuHandler selector); }; /** CCMenuItemSprite accepts CCNode objects as items. @@ -184,7 +184,7 @@ namespace cocos2d{ /** creates a menu item with a normal,selected and disabled image with target/selector */ static CCMenuItemSprite * itemFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MunuHandler selector); /** initializes a menu item with a normal, selected and disabled image with target/selector */ - CCMenuItemSprite * initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MunuHandler selector); + bool initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MunuHandler selector); // super methods virtual void draw(); virtual void setColor(ccColor3B color){} @@ -217,7 +217,7 @@ namespace cocos2d{ /** creates a menu item with a normal,selected and disabled image with target/selector */ static CCMenuItemImage* itemFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector); /** initializes a menu item with a normal, selected and disabled image with target/selector */ - CCMenuItemImage* initFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector); + bool initFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector); // super methods virtual void setColor(ccColor3B color); virtual ccColor3B getColor(); @@ -247,7 +247,7 @@ namespace cocos2d{ /** creates a menu item from a list of items with a target/selector */ static CCMenuItemToggle* itemWithTarget(SelectorProtocol* target, SEL_MunuHandler selector, CCMenuItem* item, ...); /** initializes a menu item from a list of items with a target selector */ - CCMenuItemToggle* initWithTarget(SelectorProtocol* target, SEL_MunuHandler selector, CCMenuItem* item, va_list args); + bool initWithTarget(SelectorProtocol* target, SEL_MunuHandler selector, CCMenuItem* item, va_list args); /** return the selected item */ CCMenuItem* selectedItem(); // super methods diff --git a/cocos2dx/include/CCPageTurnTransition.h b/cocos2dx/include/CCPageTurnTransition.h index 3f92d59e5b..cd646ecd37 100644 --- a/cocos2dx/include/CCPageTurnTransition.h +++ b/cocos2dx/include/CCPageTurnTransition.h @@ -60,7 +60,7 @@ public: * if back is TRUE then the effect is reversed to appear as if the incoming * scene is being turned from left over the outgoing scene */ - virtual CCPageTurnTransition* initWithDuration(ccTime t,CCScene* scene,bool backwards); + virtual bool initWithDuration(ccTime t,CCScene* scene,bool backwards); CCIntervalAction* actionWithSize(ccGridSize vector); diff --git a/cocos2dx/include/CCRibbon.h b/cocos2dx/include/CCRibbon.h index 210eeb1f98..1e4cb6bfeb 100644 --- a/cocos2dx/include/CCRibbon.h +++ b/cocos2dx/include/CCRibbon.h @@ -103,7 +103,7 @@ namespace cocos2d { CCRibbonSegment(){} virtual ~CCRibbonSegment(); char * description(); - CCRibbonSegment * init(); + bool init(); void reset(); void draw(float curTime, float fadeTime, ccColor4B color); }; diff --git a/cocos2dx/include/CCSprite.h b/cocos2dx/include/CCSprite.h index 907174943c..c8ea224337 100644 --- a/cocos2dx/include/CCSprite.h +++ b/cocos2dx/include/CCSprite.h @@ -197,7 +197,7 @@ public: static CCSprite* spriteWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect rect, CGPoint offset); public: - CCSprite* init(void); + bool init(void); virtual ~CCSprite(void); CCSprite() {} @@ -242,33 +242,33 @@ public: The rect used will be the size of the texture. The offset will be (0,0). */ - CCSprite* initWithTexture(CCTexture2D *pTexture); + bool initWithTexture(CCTexture2D *pTexture); /** Initializes an sprite with a texture and a rect. The offset will be (0,0). */ - CCSprite* initWithTexture(CCTexture2D *pTexture, CGRect rect); + bool initWithTexture(CCTexture2D *pTexture, CGRect rect); // Initializes an sprite with an sprite frame. - CCSprite* initWithSpriteFrame(CCSpriteFrame *pSpriteFrame); + bool initWithSpriteFrame(CCSpriteFrame *pSpriteFrame); /** Initializes an sprite with an sprite frame name. An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name. If the CCSpriteFrame doesn't exist it will raise an exception. @since v0.9 */ - CCSprite* initWithSpriteFrameName(const char *pszSpriteFrameName); + bool initWithSpriteFrameName(const char *pszSpriteFrameName); /** Initializes an sprite with an image filename. The rect used will be the size of the image. The offset will be (0,0). */ - CCSprite* initWithFile(const char *pszFilename); + bool initWithFile(const char *pszFilename); /** Initializes an sprite with an image filename, and a rect. The offset will be (0,0). */ - CCSprite* initWithFile(const char *pszFilename, CGRect rect); + bool initWithFile(const char *pszFilename, CGRect rect); /** Initializes an sprite with a CGImageRef @deprecated Use spriteWithCGImage:key: instead. Will be removed in v1.0 final @@ -284,7 +284,7 @@ public: // CCSprite* initWithCGImage(CGImageRef pImage, const char *pszKey); // Initializes an sprite with an CCSpriteSheet and a rect - CCSprite* initWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect rect); + bool initWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect rect); // sprite sheet methods diff --git a/cocos2dx/include/CCSpriteFrame.h b/cocos2dx/include/CCSpriteFrame.h index 33417aac84..fc7f728790 100644 --- a/cocos2dx/include/CCSpriteFrame.h +++ b/cocos2dx/include/CCSpriteFrame.h @@ -95,12 +95,12 @@ public: /** Initializes a CCSpriteFrame with a texture, rect and offset. It is assumed that the frame was not trimmed. */ - CCSpriteFrame* initWithTexture(CCTexture2D* pobTexture, CGRect rect, CGPoint offset); + bool initWithTexture(CCTexture2D* pobTexture, CGRect rect, CGPoint offset); /** Initializes a CCSpriteFrame with a texture, rect, offset and originalSize. The originalSize is the size in pixels of the frame before being trimmed. */ - CCSpriteFrame* initWithTexture(CCTexture2D* pobTexture, CGRect rect, CGPoint offset, CGSize originalSize); + bool initWithTexture(CCTexture2D* pobTexture, CGRect rect, CGPoint offset, CGSize originalSize); protected: CGRect m_obRect; CGPoint m_obOffset; @@ -154,18 +154,18 @@ public: /** Initializes a CCAnimation with a name @since v0.99.3 */ - CCAnimation* initWithName(const char *pszName); + bool initWithName(const char *pszName); /** Initializes a CCAnimation with a name and frames @since v0.99.3 */ - CCAnimation* initWithName(const char *pszName, NSArray *pFrames); + bool initWithName(const char *pszName, NSArray *pFrames); // Initializes a CCAnimation with a name and delay between frames. - CCAnimation* initWithName(const char *pszName, float fDelay); + bool initWithName(const char *pszName, float fDelay); // Initializes a CCAnimation with a name, delay and an array of CCSpriteFrames. - CCAnimation* initWithName(const char *pszName, float fDelay, NSArray *pFrames); + bool initWithName(const char *pszName, float fDelay, NSArray *pFrames); // adds a frame to a CCAnimation void addFrame(CCSpriteFrame *pFrame); diff --git a/cocos2dx/include/CCSpriteFrameCache.h b/cocos2dx/include/CCSpriteFrameCache.h index 2d996c8966..de7109f16c 100644 --- a/cocos2dx/include/CCSpriteFrameCache.h +++ b/cocos2dx/include/CCSpriteFrameCache.h @@ -48,7 +48,7 @@ class CCSprite; class CCSpriteFrameCache : public NSObject { public: - CCSpriteFrameCache* init(void); + bool init(void); ~CCSpriteFrameCache(void); /*Adds multiple Sprite Frames with a dictionary. The texture will be associated with the created sprite frames. diff --git a/cocos2dx/include/CCSpriteSheet.h b/cocos2dx/include/CCSpriteSheet.h index 32f9ea2cda..f25b6376fc 100644 --- a/cocos2dx/include/CCSpriteSheet.h +++ b/cocos2dx/include/CCSpriteSheet.h @@ -59,13 +59,13 @@ public: /** initializes a CCSpriteSheet with a texture2d and capacity of children. The capacity will be increased in 33% in runtime if it run out of space. */ - CCSpriteSheet* initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity); + bool initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity); /** initializes a CCSpriteSheet with a file image (.png, .jpeg, .pvr, etc) and a capacity of children. The capacity will be increased in 33% in runtime if it run out of space. The file will be loaded using the TextureMgr. */ - CCSpriteSheet* initWithFile(const char *pszFileImage, unsigned int uCapacity); + bool initWithFile(const char *pszFileImage, unsigned int uCapacity); void increaseAtlasCapacity(void); diff --git a/cocos2dx/include/CCTexture2D.h b/cocos2dx/include/CCTexture2D.h index 2156d92714..2af4e065ed 100644 --- a/cocos2dx/include/CCTexture2D.h +++ b/cocos2dx/include/CCTexture2D.h @@ -114,7 +114,7 @@ public: char * description(void); /** Intializes with a texture2d with data */ - CCTexture2D * initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize); + bool initWithData(const void* data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize); /** Drawing extensions to make it easy to draw basic quads using a CCTexture2D object. @@ -130,16 +130,16 @@ public: Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA). */ /** Initializes a texture from a UIImage object */ - CCTexture2D * initWithImage(UIImage * uiImage); + bool initWithImage(UIImage * uiImage); /** Extensions to make it easy to create a CCTexture2D object from a string of text. Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). */ /** Initializes a texture from a string with dimensions, alignment, font name and font size */ - CCTexture2D * initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize); + bool initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize); /** Initializes a texture from a string with font name and font size */ - CCTexture2D * initWithString(const char *text, const char *fontName, float fontSize); + bool initWithString(const char *text, const char *fontName, float fontSize); #ifdef _POWERVR_SUPPORT_ /** @@ -147,9 +147,9 @@ public: Note that the generated textures don't have their alpha premultiplied - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). */ /** Initializes a texture from a PVRTC buffer */ - CCTexture2D * initWithPVRTCData(const void* data, int level, int bpp, bool hasAlpha, int length); + bool initWithPVRTCData(const void* data, int level, int bpp, bool hasAlpha, int length); /** Initializes a texture from a PVRTC file */ - CCTexture2D * initWithPVRTCFile(const char* file); + bool initWithPVRTCFile(const char* file); #endif /** sets the min filter, mag filter, wrap s and wrap t texture parameters. @@ -204,7 +204,7 @@ public: static CCTexture2DPixelFormat defaultAlphaPixelFormat(); private: - CCTexture2D * initPremultipliedATextureWithImage(UIImage * image, unsigned int pixelsWide, unsigned int pixelsHigh); + bool initPremultipliedATextureWithImage(UIImage * image, unsigned int pixelsWide, unsigned int pixelsHigh); }; }//namespace cocos2d diff --git a/cocos2dx/include/CCTextureAtlas.h b/cocos2dx/include/CCTextureAtlas.h index fdc64672a8..4f9f30c236 100644 --- a/cocos2dx/include/CCTextureAtlas.h +++ b/cocos2dx/include/CCTextureAtlas.h @@ -79,7 +79,7 @@ public: * * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ - CCTextureAtlas * initWithFile(const char* file, unsigned int capacity); + bool initWithFile(const char* file, unsigned int capacity); /** creates a TextureAtlas with a previously initialized Texture2D object, and * with an initial capacity for n Quads. @@ -93,7 +93,7 @@ public: * * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706) */ - CCTextureAtlas * initWithTexture(CCTexture2D *texture, unsigned int capacity); + bool initWithTexture(CCTexture2D *texture, unsigned int capacity); /** updates a Quad (texture, vertex and color) at a certain index * index must be between 0 and the atlas capacity - 1 diff --git a/cocos2dx/include/CCTouchDispatcher.h b/cocos2dx/include/CCTouchDispatcher.h index 46d923f5aa..2229431af2 100644 --- a/cocos2dx/include/CCTouchDispatcher.h +++ b/cocos2dx/include/CCTouchDispatcher.h @@ -91,7 +91,7 @@ class CCX_DLL CCTouchDispatcher : public NSObject, public EGLTouchDelegate { public: ~CCTouchDispatcher(); - CCTouchDispatcher* init(void); + bool init(void); CCTouchDispatcher() {} public: diff --git a/cocos2dx/include/CCTransition.h b/cocos2dx/include/CCTransition.h index 0db61bf654..752942731c 100644 --- a/cocos2dx/include/CCTransition.h +++ b/cocos2dx/include/CCTransition.h @@ -87,7 +87,7 @@ public: static CCTransitionScene * transitionWithDuration(ccTime t, CCScene *scene); /** initializes a transition with duration and incoming scene */ - virtual CCTransitionScene * initWithDuration(ccTime t,CCScene* scene); + virtual bool initWithDuration(ccTime t,CCScene* scene); /** called after the transition finishes */ void finish(void); @@ -117,7 +117,7 @@ public: /** creates a base transition with duration and incoming scene */ static CCOrientedTransitionScene * transitionWithDuration(ccTime t,CCScene* scene, tOrientation orientation); /** initializes a transition with duration and incoming scene */ - virtual CCOrientedTransitionScene * initWithDuration(ccTime t,CCScene* scene,tOrientation orientation); + virtual bool initWithDuration(ccTime t,CCScene* scene,tOrientation orientation); }; /** CCRotoZoomTransition: @@ -408,9 +408,9 @@ public: */ static CCFadeTransition* transitionWithDuration(ccTime duration,CCScene* scene, ccColor3B color = ccBLACK); /** initializes the transition with a duration and with an RGB color */ - virtual CCFadeTransition* initWithDuration(ccTime t, CCScene*scene ,ccColor3B color); + virtual bool initWithDuration(ccTime t, CCScene*scene ,ccColor3B color); - virtual CCFadeTransition * initWithDuration(ccTime t,CCScene* scene); + virtual bool initWithDuration(ccTime t,CCScene* scene); virtual void onEnter(); virtual void onExit(); }; diff --git a/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp b/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp index 3f601eb05f..5d6cedac4c 100644 --- a/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp +++ b/cocos2dx/label_nodes/CCBitmapFontAtlas.cpp @@ -80,15 +80,20 @@ namespace cocos2d{ CCBitmapFontConfiguration * CCBitmapFontConfiguration::configurationWithFNTFile(const char *FNTfile) { CCBitmapFontConfiguration * pRet = new CCBitmapFontConfiguration(); - pRet->initWithFNTfile(FNTfile); - pRet->autorelease(); - return pRet; + if (pRet->initWithFNTfile(FNTfile)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } - CCBitmapFontConfiguration * CCBitmapFontConfiguration::initWithFNTfile(const char *FNTfile) + bool CCBitmapFontConfiguration::initWithFNTfile(const char *FNTfile) { + assert(FNTfile != NULL && strlen(FNTfile)!=0); m_pKerningDictionary = NULL; this->parseConfigFile(FNTfile); - return this; + return true; } CCBitmapFontConfiguration::~CCBitmapFontConfiguration() { @@ -357,8 +362,9 @@ namespace cocos2d{ CCX_SAFE_DELETE(pRet) return NULL; } - CCBitmapFontAtlas * CCBitmapFontAtlas::initWithString(const char *theString, const char *fntFile) + bool CCBitmapFontAtlas::initWithString(const char *theString, const char *fntFile) { + assert(theString != NULL); CCX_SAFE_RELEASE(m_pConfiguration);// allow re-init m_pConfiguration = FNTConfigLoadFile(fntFile); m_pConfiguration->retain(); @@ -372,9 +378,9 @@ namespace cocos2d{ m_bIsOpacityModifyRGB = m_pobTextureAtlas->getTexture()->getHasPremultipliedAlpha(); m_tAnchorPoint = ccp(0.5f, 0.5f); this->setString(theString); - return this; + return true; } - return NULL; + return false; } CCBitmapFontAtlas::~CCBitmapFontAtlas() { diff --git a/cocos2dx/label_nodes/CCLabel.cpp b/cocos2dx/label_nodes/CCLabel.cpp index 47d8d54ac7..bd2e1ae305 100644 --- a/cocos2dx/label_nodes/CCLabel.cpp +++ b/cocos2dx/label_nodes/CCLabel.cpp @@ -50,8 +50,9 @@ namespace cocos2d{ return NULL; } - CCLabel * CCLabel::initWithString(const char *label, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) + bool CCLabel::initWithString(const char *label, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) { + assert(label != NULL); if (CCSprite::init()) { m_tDimensions = dimensions; @@ -59,21 +60,22 @@ namespace cocos2d{ m_sFontName = fontName; m_fFontSize = fontSize; this->setString(label); - return this; + return true; } - return NULL; + return false; } - CCLabel * CCLabel::initWithString(const char *label, const char *fontName, float fontSize) + bool CCLabel::initWithString(const char *label, const char *fontName, float fontSize) { + assert(label != NULL); if (CCSprite::init()) { m_tDimensions = CGSizeZero; m_sFontName = fontName; m_fFontSize = fontSize; this->setString(label); - return this; + return true; } - return NULL; + return false; } void CCLabel::setString(const char *label) { diff --git a/cocos2dx/label_nodes/CCLabelAtlas.cpp b/cocos2dx/label_nodes/CCLabelAtlas.cpp index 4991c27ad0..65ae9de1a1 100644 --- a/cocos2dx/label_nodes/CCLabelAtlas.cpp +++ b/cocos2dx/label_nodes/CCLabelAtlas.cpp @@ -37,15 +37,16 @@ namespace cocos2d{ CCX_SAFE_DELETE(pRet) return NULL; } - CCLabelAtlas * CCLabelAtlas::initWithString(const char *label, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap) + bool CCLabelAtlas::initWithString(const char *label, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap) { + assert(label != NULL); if (CCAtlasNode::initWithTileFile(charMapFile, itemWidth, itemHeight, strlen(label))) { m_cMapStartChar = startCharMap; this->setString(label); - return this; + return true; } - return NULL; + return false; } //CCLabelAtlas - Atlas generation diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index ff8e39b8eb..be7baea188 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -223,19 +223,27 @@ void CCColorLayer::setBlendFunc(ccBlendFunc var) CCColorLayer * CCColorLayer::layerWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) { CCColorLayer * pLayer = new CCColorLayer(); - pLayer->initWithColorWidthHeight(color,width,height); - pLayer->autorelease(); - return pLayer; + if( pLayer && pLayer->initWithColorWidthHeight(color,width,height)) + { + pLayer->autorelease(); + return pLayer; + } + CCX_SAFE_DELETE(pLayer); + return NULL; } CCColorLayer * CCColorLayer::layerWithColor(ccColor4B color) { CCColorLayer * pLayer = new CCColorLayer(); - pLayer->initWithColor(color); - pLayer->autorelease(); - return pLayer; + if(pLayer && pLayer->initWithColor(color)) + { + pLayer->autorelease(); + return pLayer; + } + CCX_SAFE_DELETE(pLayer); + return NULL; } -CCColorLayer* CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) +bool CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height) { // default blend function m_tBlendFunc.src = CC_BLEND_SRC; @@ -247,17 +255,20 @@ CCColorLayer* CCColorLayer::initWithColorWidthHeight(ccColor4B color, GLfloat wi m_cOpacity = color.a; for (unsigned int i=0; iupdateColor(); this->setContentSize(CGSizeMake(width,height)); - return this; + return true; } -CCColorLayer * CCColorLayer::initWithColor(ccColor4B color) +bool CCColorLayer::initWithColor(ccColor4B color) { CGSize s = CCDirector::getSharedDirector()->getWinSize(); - return this->initWithColorWidthHeight(color, s.width, s.height); + this->initWithColorWidthHeight(color, s.width, s.height); + return true; } /// override contentSize @@ -349,14 +360,18 @@ CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...) va_start(args,layer); CCMultiplexLayer * pMultiplexLayer = new CCMultiplexLayer(); - pMultiplexLayer->initWithLayers(layer, args); - pMultiplexLayer->autorelease(); - + if(pMultiplexLayer && pMultiplexLayer->initWithLayers(layer, args)) + { + pMultiplexLayer->autorelease(); + va_end(args); + return pMultiplexLayer; + } va_end(args); - return pMultiplexLayer; + CCX_SAFE_DELETE(pMultiplexLayer); + return NULL; } -CCMultiplexLayer * CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list params) +bool CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list params) { m_pLayers = new NSMutableArray(5); m_pLayers->retain(); @@ -372,7 +387,7 @@ CCMultiplexLayer * CCMultiplexLayer::initWithLayers(CCLayer *layer, va_list para m_nEnabledLayer = 0; this->addChild(m_pLayers->getObjectAtIndex(m_nEnabledLayer)); - return this; + return true; } diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCPageTurnTransition.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCPageTurnTransition.cpp index 90e8772cd1..b85091350f 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCPageTurnTransition.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCPageTurnTransition.cpp @@ -48,7 +48,7 @@ CCPageTurnTransition * CCPageTurnTransition::transitionWithDuration(ccTime t, CC } /** initializes a transition with duration and incoming scene */ -CCPageTurnTransition * CCPageTurnTransition::initWithDuration(ccTime t, CCScene *scene, bool backwards) +bool CCPageTurnTransition::initWithDuration(ccTime t, CCScene *scene, bool backwards) { // XXX: needed before [super init] m_bBack = backwards; @@ -57,7 +57,7 @@ CCPageTurnTransition * CCPageTurnTransition::initWithDuration(ccTime t, CCScene { // do something } - return this; + return true; } void CCPageTurnTransition::sceneOrder() diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp index b0f0601edd..36baf70d93 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCTransition.cpp @@ -45,9 +45,11 @@ enum { _Type* _Type::transitionWithDuration(ccTime t, CCScene* scene)\ {\ _Type* pScene = new _Type();\ - pScene->initWithDuration(t, scene);\ + if(pScene && pScene->initWithDuration(t, scene)){\ pScene->autorelease();\ - return pScene;\ + return pScene;}\ + CCX_SAFE_DELETE(pScene);\ + return NULL;\ } @@ -64,12 +66,16 @@ CCTransitionScene::~CCTransitionScene() CCTransitionScene * CCTransitionScene::transitionWithDuration(ccTime t, CCScene *scene) { CCTransitionScene * pScene = new CCTransitionScene(); - pScene->initWithDuration(t,scene); - pScene->autorelease(); - return pScene; + if(pScene && pScene->initWithDuration(t,scene)) + { + pScene->autorelease(); + return pScene; + } + CCX_SAFE_DELETE(pScene); + return NULL; } -CCTransitionScene * CCTransitionScene::initWithDuration(ccTime t, CCScene *scene) +bool CCTransitionScene::initWithDuration(ccTime t, CCScene *scene) { NSAssert( scene != NULL, "Argument scene must be non-nil"); @@ -90,11 +96,11 @@ CCTransitionScene * CCTransitionScene::initWithDuration(ccTime t, CCScene *scene CCTouchDispatcher::getSharedDispatcher()->setDispatchEvents(false); this->sceneOrder(); - return this; + return true; } else { - return NULL; + return false; } } @@ -203,13 +209,13 @@ CCOrientedTransitionScene * CCOrientedTransitionScene::transitionWithDuration(cc return pScene; } -CCOrientedTransitionScene * CCOrientedTransitionScene::initWithDuration(ccTime t, CCScene *scene, tOrientation orientation) +bool CCOrientedTransitionScene::initWithDuration(ccTime t, CCScene *scene, tOrientation orientation) { if ( CCTransitionScene::initWithDuration(t, scene) ) { m_eOrientation = orientation; } - return this; + return true; } // @@ -1034,7 +1040,7 @@ CCFadeTransition * CCFadeTransition::transitionWithDuration(ccTime duration, CCS return pTransition; } -CCFadeTransition * CCFadeTransition::initWithDuration(ccTime duration, CCScene *scene, ccColor3B color) +bool CCFadeTransition::initWithDuration(ccTime duration, CCScene *scene, ccColor3B color) { if (CCTransitionScene::initWithDuration(duration, scene)) { @@ -1042,13 +1048,13 @@ CCFadeTransition * CCFadeTransition::initWithDuration(ccTime duration, CCScene * m_tColor.g = color.g; m_tColor.b = color.b; } - return this; + return true; } -CCFadeTransition * CCFadeTransition::initWithDuration(ccTime t, CCScene *scene) +bool CCFadeTransition::initWithDuration(ccTime t, CCScene *scene) { this->initWithDuration(t, scene, ccBLACK); - return this; + return true; } void CCFadeTransition :: onEnter() diff --git a/cocos2dx/menu_nodes/CCMenu.cpp b/cocos2dx/menu_nodes/CCMenu.cpp index 314bd7fe30..8e00380799 100644 --- a/cocos2dx/menu_nodes/CCMenu.cpp +++ b/cocos2dx/menu_nodes/CCMenu.cpp @@ -59,7 +59,7 @@ namespace cocos2d{ return NULL; } - CCMenu * CCMenu::initWithItems(CCMenuItem* item, va_list args) + bool CCMenu::initWithItems(CCMenuItem* item, va_list args) { if (CCLayer::init()) { @@ -103,10 +103,10 @@ namespace cocos2d{ m_pSelectedItem = NULL; m_eState = kMenuStateWaiting; - return this; + return true; } - return NULL; + return false; } /* diff --git a/cocos2dx/menu_nodes/CCMenuItem.cpp b/cocos2dx/menu_nodes/CCMenuItem.cpp index 71c909c1af..ea18801772 100644 --- a/cocos2dx/menu_nodes/CCMenuItem.cpp +++ b/cocos2dx/menu_nodes/CCMenuItem.cpp @@ -54,14 +54,14 @@ namespace cocos2d{ pRet->autorelease(); return pRet; } - CCMenuItem * CCMenuItem::initWithTarget(SelectorProtocol *rec, SEL_MunuHandler selector) + bool CCMenuItem::initWithTarget(SelectorProtocol *rec, SEL_MunuHandler selector) { m_tAnchorPoint = ccp(0.5f, 0.5f); m_pListener = rec; m_pfnSelector = selector; m_bIsEnabled = true; m_bIsSelected = false; - return this; + return true; } void CCMenuItem::selected() { @@ -125,14 +125,14 @@ namespace cocos2d{ pRet->autorelease(); return pRet; } - CCMenuItemLabel * CCMenuItemLabel::initWithLabel(CCNode* label, SelectorProtocol* target, SEL_MunuHandler selector) + bool CCMenuItemLabel::initWithLabel(CCNode* label, SelectorProtocol* target, SEL_MunuHandler selector) { CCMenuItem::initWithTarget(target, selector); m_fOriginalScale = 1.0f; m_tColorBackup = ccWHITE; m_tDisabledColor = ccc3(126,126,126); this->setLabel(label); - return this; + return true; } CCMenuItemLabel::~CCMenuItemLabel() { @@ -231,9 +231,9 @@ namespace cocos2d{ pRet->autorelease(); return pRet; } - CCMenuItemAtlasFont * CCMenuItemAtlasFont::initFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol* target, SEL_MunuHandler selector) + bool CCMenuItemAtlasFont::initFromString(const char *value, const char *charMapFile, int itemWidth, int itemHeight, char startCharMap, SelectorProtocol* target, SEL_MunuHandler selector) { - NSAssert( strlen(value) != 0, "value lenght must be greater than 0"); + NSAssert( value != NULL && strlen(value) != 0, "value lenght must be greater than 0"); CCLabelAtlas *label = new CCLabelAtlas(); label->initWithString(value, charMapFile, itemWidth, itemHeight, startCharMap); label->autorelease(); @@ -241,7 +241,7 @@ namespace cocos2d{ { // do something ? } - return this; + return true; } // //CCMenuItemFont @@ -281,15 +281,15 @@ namespace cocos2d{ pRet->autorelease(); return pRet; } - CCMenuItemFont * CCMenuItemFont::initFromString(const char *value, SelectorProtocol* target, SEL_MunuHandler selector) + bool CCMenuItemFont::initFromString(const char *value, SelectorProtocol* target, SEL_MunuHandler selector) { - NSAssert( strlen(value) != 0, "Value lenght must be greater than 0"); + NSAssert( value != NULL && strlen(value) != 0, "Value lenght must be greater than 0"); CCLabel *label = CCLabel::labelWithString(value, _fontName.c_str(), (float)_fontSize); if (CCMenuItemLabel::initWithLabel(label, target, selector)) { // do something ? } - return this; + return true; } // //CCMenuItemSprite @@ -333,14 +333,15 @@ namespace cocos2d{ pRet->autorelease(); return pRet; } - CCMenuItemSprite * CCMenuItemSprite::initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MunuHandler selector) + bool CCMenuItemSprite::initFromNormalSprite(CCNode* normalSprite, CCNode* selectedSprite, CCNode* disabledSprite, SelectorProtocol* target, SEL_MunuHandler selector) { + assert(normalSprite != NULL); CCMenuItem::initWithTarget(target, selector); this->m_pNormalImage = normalSprite; CCX_SAFE_RETAIN(normalSprite); this->m_pSelectedImage = selectedSprite; CCX_SAFE_RETAIN(selectedSprite); this->m_pDisabledImage = disabledSprite; CCX_SAFE_RETAIN(disabledSprite); this->setContentSize(m_pNormalImage->getContentSize()); - return this; + return true; } CCMenuItemSprite::~CCMenuItemSprite() { @@ -416,26 +417,36 @@ namespace cocos2d{ CCMenuItemImage * CCMenuItemImage::itemFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector) { CCMenuItemImage *pRet = new CCMenuItemImage(); - pRet->initFromNormalImage(normalImage, selectedImage, disabledImage, target, selector); - pRet->autorelease(); - return pRet; + if (pRet && pRet->initFromNormalImage(normalImage, selectedImage, disabledImage, target, selector)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } CCMenuItemImage * CCMenuItemImage::itemFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage) { CCMenuItemImage *pRet = new CCMenuItemImage(); - pRet->initFromNormalImage(normalImage, selectedImage, disabledImage, NULL, NULL); - pRet->autorelease(); - return pRet; + if (pRet && pRet->initFromNormalImage(normalImage, selectedImage, disabledImage, NULL, NULL)) + { + pRet->autorelease(); + return pRet; + } + CCX_SAFE_DELETE(pRet); + return NULL; } - CCMenuItemImage * CCMenuItemImage::initFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector) + bool CCMenuItemImage::initFromNormalImage(const char *normalImage, const char *selectedImage, const char *disabledImage, SelectorProtocol* target, SEL_MunuHandler selector) { CCNode *normalSprite = CCSprite::spriteWithFile(normalImage); CCNode *selectedSprite = CCSprite::spriteWithFile(selectedImage); CCNode *disabledSprite = NULL; if(disabledImage) + { disabledSprite = CCSprite::spriteWithFile(disabledImage); - return (CCMenuItemImage*)(initFromNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector)); + } + return initFromNormalSprite(normalSprite, selectedSprite, disabledSprite, target, selector); } // // MenuItemToggle @@ -458,7 +469,7 @@ namespace cocos2d{ va_end(args); return pRet; } - CCMenuItemToggle * CCMenuItemToggle::initWithTarget(SelectorProtocol* target, SEL_MunuHandler selector, CCMenuItem* item, va_list args) + bool CCMenuItemToggle::initWithTarget(SelectorProtocol* target, SEL_MunuHandler selector, CCMenuItem* item, va_list args) { CCMenuItem::initWithTarget(target, selector); this->m_pSubItems = new NSMutableArray(); @@ -472,7 +483,7 @@ namespace cocos2d{ } m_uSelectedIndex = UINT_MAX; this->setSelectedIndex(0); - return this; + return true; } CCMenuItemToggle::~CCMenuItemToggle() { diff --git a/cocos2dx/misc_nodes/CCRibbon.cpp b/cocos2dx/misc_nodes/CCRibbon.cpp index 54e5714d15..1ec0157ea1 100644 --- a/cocos2dx/misc_nodes/CCRibbon.cpp +++ b/cocos2dx/misc_nodes/CCRibbon.cpp @@ -320,10 +320,10 @@ namespace cocos2d { // //RibbonSegment // - CCRibbonSegment * CCRibbonSegment::init() + bool CCRibbonSegment::init() { this->reset(); - return this; + return true; } char * CCRibbonSegment::description() { diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 0391899c3d..36e53a32f1 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -144,7 +144,7 @@ CCSprite* CCSprite::spriteWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect re return pobSprite; } -CCSprite* CCSprite::init(void) +bool CCSprite::init(void) { m_bDirty = m_bRecursiveDirty = false; @@ -194,10 +194,10 @@ CCSprite* CCSprite::init(void) // Atlas: TexCoords setTextureRect(CGRectZero); - return this; + return true; } -CCSprite* CCSprite::initWithTexture(CCTexture2D *pTexture, CGRect rect) +bool CCSprite::initWithTexture(CCTexture2D *pTexture, CGRect rect) { assert(pTexture != NULL); // IMPORTANT: [self init] and not [super init]; @@ -205,10 +205,10 @@ CCSprite* CCSprite::initWithTexture(CCTexture2D *pTexture, CGRect rect) setTexture(pTexture); setTextureRect(rect); - return this; + return true; } -CCSprite* CCSprite::initWithTexture(CCTexture2D *pTexture) +bool CCSprite::initWithTexture(CCTexture2D *pTexture) { assert(pTexture != NULL); @@ -218,7 +218,7 @@ CCSprite* CCSprite::initWithTexture(CCTexture2D *pTexture) return initWithTexture(pTexture, rect); } -CCSprite* CCSprite::initWithFile(const char *pszFilename) +bool CCSprite::initWithFile(const char *pszFilename) { assert(pszFilename != NULL); @@ -231,10 +231,10 @@ CCSprite* CCSprite::initWithFile(const char *pszFilename) } this->release(); - return NULL; + return false; } -CCSprite* CCSprite::initWithFile(const char *pszFilename, CGRect rect) +bool CCSprite::initWithFile(const char *pszFilename, CGRect rect) { assert(pszFilename != NULL); @@ -245,20 +245,20 @@ CCSprite* CCSprite::initWithFile(const char *pszFilename, CGRect rect) } this->release(); - return NULL; + return false; } -CCSprite* CCSprite::initWithSpriteFrame(CCSpriteFrame *pSpriteFrame) +bool CCSprite::initWithSpriteFrame(CCSpriteFrame *pSpriteFrame) { assert(pSpriteFrame != NULL); - CCSprite* pRet = initWithTexture(pSpriteFrame->getTexture(), pSpriteFrame->getRect()); + bool bRet = initWithTexture(pSpriteFrame->getTexture(), pSpriteFrame->getRect()); setDisplayFrame(pSpriteFrame); - return pRet; + return bRet; } -CCSprite* CCSprite::initWithSpriteFrameName(const char *pszSpriteFrameName) +bool CCSprite::initWithSpriteFrameName(const char *pszSpriteFrameName) { assert(pszSpriteFrameName != NULL); @@ -292,12 +292,13 @@ CCSprite* CCSprite::initWithCGImage(CGImageRef pImage, const char *pszKey) } */ -CCSprite* CCSprite::initWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect rect) +bool CCSprite::initWithSpriteSheet(CCSpriteSheet *pSpriteSheet, CGRect rect) { - CCSprite* pRet = initWithTexture(pSpriteSheet->getTexture(), rect); + assert(pSpriteSheet != NULL); + bool bRet = initWithTexture(pSpriteSheet->getTexture(), rect); useSpriteSheetRender(pSpriteSheet); - return pRet; + return bRet; } CCSprite::~CCSprite(void) diff --git a/cocos2dx/sprite_nodes/CCSpriteFrame.cpp b/cocos2dx/sprite_nodes/CCSpriteFrame.cpp index df05544aff..a5220096ee 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrame.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteFrame.cpp @@ -67,22 +67,22 @@ CCAnimation* CCAnimation::animationWithName(const char *pszName, float fDelay) return pAnimation; } -CCAnimation* CCAnimation::initWithName(const char *pszName) +bool CCAnimation::initWithName(const char *pszName) { return initWithName(pszName, 0, NULL); } -CCAnimation* CCAnimation::initWithName(const char *pszName, float fDelay) +bool CCAnimation::initWithName(const char *pszName, float fDelay) { return initWithName(pszName, fDelay, NULL); } -CCAnimation* CCAnimation::initWithName(const char *pszName, NSMutableArray *pFrames) +bool CCAnimation::initWithName(const char *pszName, NSMutableArray *pFrames) { return initWithName(pszName, 0, pFrames); } -CCAnimation* CCAnimation::initWithName(const char *pszName, float fDelay, NSMutableArray *pFrames) +bool CCAnimation::initWithName(const char *pszName, float fDelay, NSMutableArray *pFrames) { m_fDelay = fDelay; m_pszName = new char[strlen(pszName) + 1]; @@ -90,7 +90,7 @@ CCAnimation* CCAnimation::initWithName(const char *pszName, float fDelay, NSMuta m_pszName[strlen(pszName)] = '\0'; m_pobFrames = NSMutableArray::arrayWithArray(pFrames); - return this; + return true; } CCAnimation::~CCAnimation(void) @@ -142,12 +142,12 @@ CCSpriteFrame* CCSpriteFrame::frameWithTexture(CCTexture2D *pobTexture, CGRect r return pSpriteFrame; } -CCSpriteFrame* CCSpriteFrame::initWithTexture(CCTexture2D *pobTexture, CGRect rect, CGPoint offset) +bool CCSpriteFrame::initWithTexture(CCTexture2D *pobTexture, CGRect rect, CGPoint offset) { return initWithTexture(pobTexture, rect, offset, rect.size); } -CCSpriteFrame* CCSpriteFrame::initWithTexture(CCTexture2D *pobTexture, CGRect rect, CGPoint offset, CGSize originalSize) +bool CCSpriteFrame::initWithTexture(CCTexture2D *pobTexture, CGRect rect, CGPoint offset, CGSize originalSize) { m_pobTexture = pobTexture; pobTexture->retain(); @@ -155,7 +155,7 @@ CCSpriteFrame* CCSpriteFrame::initWithTexture(CCTexture2D *pobTexture, CGRect re m_obRect = rect; m_obOriginalSize = originalSize; - return this; + return true; } CCSpriteFrame::~CCSpriteFrame(void) diff --git a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp index 3b66f141be..e2b6ffc685 100644 --- a/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteFrameCache.cpp @@ -52,10 +52,10 @@ void CCSpriteFrameCache::purgeSharedSpriteFrameCache(void) CCX_SAFE_RELEASE_NULL(pSharedSpriteFrameCache); } -CCSpriteFrameCache* CCSpriteFrameCache::init(void) +bool CCSpriteFrameCache::init(void) { m_pSpriteFramesMap = new map(); - return this; + return true; } CCSpriteFrameCache::~CCSpriteFrameCache(void) diff --git a/cocos2dx/sprite_nodes/CCSpriteSheet.cpp b/cocos2dx/sprite_nodes/CCSpriteSheet.cpp index 8a54508039..c7d7548976 100644 --- a/cocos2dx/sprite_nodes/CCSpriteSheet.cpp +++ b/cocos2dx/sprite_nodes/CCSpriteSheet.cpp @@ -73,7 +73,7 @@ CCSpriteSheet* CCSpriteSheet::spriteSheetWithFile(const char *pszFileImage) } // init with CCTexture2D -CCSpriteSheet* CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity) +bool CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, unsigned int uCapacity) { m_blendFunc.src = CC_BLEND_SRC; m_blendFunc.dst = CC_BLEND_DST; @@ -87,11 +87,11 @@ CCSpriteSheet* CCSpriteSheet::initWithTexture(CCTexture2D *pobTexture, unsigned m_pChildren = new NSMutableArray(); m_pobDescendants = new NSMutableArray(); - return this; + return true; } // init with FileImage -CCSpriteSheet* CCSpriteSheet::initWithFile(const char *pszFileImage, unsigned int uCapacity) +bool CCSpriteSheet::initWithFile(const char *pszFileImage, unsigned int uCapacity) { CCTexture2D *pTexture2D = CCTextureCache::sharedTextureCache()->addImage(pszFileImage); return initWithTexture(pTexture2D, uCapacity); diff --git a/cocos2dx/textures/CCTexture2D.cpp b/cocos2dx/textures/CCTexture2D.cpp index 23d09e7c1f..cbe66d2a73 100644 --- a/cocos2dx/textures/CCTexture2D.cpp +++ b/cocos2dx/textures/CCTexture2D.cpp @@ -130,7 +130,7 @@ bool CCTexture2D::getHasPremultipliedAlpha() return m_bHasPremultipliedAlpha; } -CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize) +bool CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat pixelFormat, unsigned int pixelsWide, unsigned int pixelsHigh, CGSize contentSize) { glGenTextures(1, &m_uName); glBindTexture(GL_TEXTURE_2D, m_uName); @@ -170,7 +170,7 @@ CCTexture2D * CCTexture2D::initWithData(const void *data, CCTexture2DPixelFormat m_bHasPremultipliedAlpha = false; - return this; + return true; } @@ -183,7 +183,7 @@ char * CCTexture2D::description(void) // implementation CCTexture2D (Image) -CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage) +bool CCTexture2D::initWithImage(UIImage * uiImage) { unsigned int POTWide, POTHigh; @@ -191,7 +191,7 @@ CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage) { CCLOG("cocos2d: CCTexture2D. Can't create Texture. UIImage is nil"); this->release(); - return NULL; + return false; } CCConfiguration *conf = CCConfiguration::sharedConfiguration(); @@ -218,10 +218,9 @@ CCTexture2D* CCTexture2D::initWithImage(UIImage * uiImage) } // always load premultiplied images - this->initPremultipliedATextureWithImage(uiImage, POTWide, POTHigh); - return this; + return initPremultipliedATextureWithImage(uiImage, POTWide, POTHigh); } -CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, unsigned int POTWide, unsigned int POTHigh) +bool CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, unsigned int POTWide, unsigned int POTHigh) { unsigned int i; void* data = NULL; @@ -364,15 +363,15 @@ CCTexture2D * CCTexture2D::initPremultipliedATextureWithImage(UIImage *image, un //CGContextRelease(context); delete [] data; } - return this; + return true; } // implementation CCTexture2D (Text) -CCTexture2D * CCTexture2D::initWithString(const char *text, const char *fontName, float fontSize) +bool CCTexture2D::initWithString(const char *text, const char *fontName, float fontSize) { return initWithString(text, CGSizeMake(0,0), UITextAlignmentCenter, fontName, fontSize); } -CCTexture2D * CCTexture2D::initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) +bool CCTexture2D::initWithString(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize) { CCXBitmapDC *pBitmapDC = new CCXBitmapDC(text, dimensions, alignment, fontName, fontSize); @@ -382,7 +381,7 @@ CCTexture2D * CCTexture2D::initWithString(const char *text, CGSize dimensions, U initWithData(pBitData, kCCTexture2DPixelFormat_RGBA8888, (UINT)size.width, (UINT)size.height, size); delete pBitmapDC; - return this; + return true; } @@ -442,13 +441,13 @@ void CCTexture2D::drawInRect(CGRect rect) // implementation CCTexture2D (PVRTC) #ifdef _POWERVR_SUPPORT_ -CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bpp, bool hasAlpha, int length) +bool CCTexture2D::initWithPVRTCData(const void *data, int level, int bpp, bool hasAlpha, int length) { if( !(CCConfiguration::sharedConfiguration()->isSupportsPVRTC()) ) { CCLOG("cocos2d: WARNING: PVRTC images is not supported."); this->release(); - return NULL; + return false; } glGenTextures(1, &m_uName); @@ -474,7 +473,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCData(const void *data, int level, int bp m_fMaxS = 1.0f; m_fMaxT = 1.0f; - return this; + return true; } CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file) @@ -483,7 +482,7 @@ CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file) { CCLOG("cocos2d: WARNING: PVRTC images is not supported"); this->release(); - return NULL; + return false; } CCPVRTexture *pvr = new CCPVRTexture(); @@ -508,9 +507,9 @@ CCTexture2D * CCTexture2D::initWithPVRTCFile(const char* file) { CCLOG("cocos2d: Couldn't load PVR image"); this->release(); - return NULL; + return false; } - return this; + return true; } #endif diff --git a/cocos2dx/textures/CCTextureAtlas.cpp b/cocos2dx/textures/CCTextureAtlas.cpp index 123e2defe2..152d3011b3 100644 --- a/cocos2dx/textures/CCTextureAtlas.cpp +++ b/cocos2dx/textures/CCTextureAtlas.cpp @@ -93,20 +93,28 @@ void CCTextureAtlas::setQuads(ccV3F_C4B_T2F_Quad *var) CCTextureAtlas * CCTextureAtlas::textureAtlasWithFile(const char* file, unsigned int capacity) { CCTextureAtlas * pTextureAtlas = new CCTextureAtlas(); - pTextureAtlas->initWithFile(file, capacity); - pTextureAtlas->autorelease(); - return pTextureAtlas; + if(pTextureAtlas && pTextureAtlas->initWithFile(file, capacity)) + { + pTextureAtlas->autorelease(); + return pTextureAtlas; + } + CCX_SAFE_DELETE(pTextureAtlas); + return NULL; } CCTextureAtlas * CCTextureAtlas::textureAtlasWithTexture(CCTexture2D *texture, unsigned int capacity) { CCTextureAtlas * pTextureAtlas = new CCTextureAtlas(); - pTextureAtlas->initWithTexture(texture, capacity); - pTextureAtlas->autorelease(); - return pTextureAtlas; + if (pTextureAtlas && pTextureAtlas->initWithTexture(texture, capacity)) + { + pTextureAtlas->autorelease(); + return pTextureAtlas; + } + CCX_SAFE_DELETE(pTextureAtlas); + return NULL; } -CCTextureAtlas * CCTextureAtlas::initWithFile(const char * file, unsigned int capacity) +bool CCTextureAtlas::initWithFile(const char * file, unsigned int capacity) { // retained in property CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(file); @@ -114,9 +122,9 @@ CCTextureAtlas * CCTextureAtlas::initWithFile(const char * file, unsigned int ca return initWithTexture(texture, capacity); } -CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity) +bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity) { - + assert(texture != NULL); m_uCapacity = capacity; m_uTotalQuads = 0; @@ -130,7 +138,7 @@ CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned CCLOG("cocos2d: CCTextureAtlas: not enough memory"); CCX_SAFE_FREE(m_pQuads) CCX_SAFE_FREE(m_pIndices) - return NULL; + return false; } #if CC_TEXTURE_ATLAS_USES_VBO @@ -140,7 +148,7 @@ CCTextureAtlas * CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned this->initIndices(); - return this; + return true; } char * CCTextureAtlas::description() diff --git a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp index 811b37e5f8..79144e133e 100644 --- a/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp +++ b/cocos2dx/touch_dispatcher/CCTouchDispatcher.cpp @@ -68,7 +68,7 @@ CCTouchDispatcher* CCTouchDispatcher::getSharedDispatcher(void) } */ -CCTouchDispatcher* CCTouchDispatcher::init(void) +bool CCTouchDispatcher::init(void) { m_bDispatchEvents = true; m_pTargetedHandlers = new NSMutableArray(8); @@ -87,7 +87,7 @@ CCTouchDispatcher* CCTouchDispatcher::init(void) m_sHandlerHelperData[ccTouchEnded].m_type = ccTouchEnded; m_sHandlerHelperData[ccTouchCancelled].m_type = ccTouchCancelled; - return this; + return true; } CCTouchDispatcher::~CCTouchDispatcher(void) diff --git a/test_uphone/test_uphoneApp.cpp b/test_uphone/test_uphoneApp.cpp index 30fc8affbc..c129c6182f 100644 --- a/test_uphone/test_uphoneApp.cpp +++ b/test_uphone/test_uphoneApp.cpp @@ -42,7 +42,8 @@ bool Ttest_uphoneApp::initCocos2d() CGSize size = CCDirector::getSharedDirector()->getWinSize(); // create sprite instance - CCSprite * pSprite = (new CCSprite())->initWithTexture(pTexture); + CCSprite * pSprite = new CCSprite(); + pSprite->initWithTexture(pTexture); pSprite->setPosition(CGPoint(size.width / 2, size.height / 2)); pSprite->autorelease()->retain();