fixed #441: Initialize pointer in contruction & detect pointer value in destruction

This commit is contained in:
minggo 2011-04-01 16:06:53 +08:00
parent 4b33a6ccb8
commit 7d52161804
42 changed files with 200 additions and 124 deletions

View File

@ -36,6 +36,14 @@ static CCConfiguration g_SharedConfiguration;
static char *g_pGlExtensions;
CCConfiguration::CCConfiguration(void)
: m_bSupportsBGRA8888(false)
, m_bSupportsDiscardFramebuffer(false)
, m_bSupportsNPOT(false)
, m_bSupportsPVRTC(false)
, m_nMaxModelviewStackDepth(0)
, m_nMaxSamplesAllowed(0)
, m_nMaxTextureSize(0)
, m_uOSVersion(0)
{
}

View File

@ -128,6 +128,14 @@ void CCTimer::update(ccTime dt)
static CCScheduler *pSharedScheduler;
CCScheduler::CCScheduler(void)
: m_bCurrentTargetSalvaged(false)
, m_fTimeScale(0.0)
, m_pCurrentTarget(NULL)
, m_pHashForSelectors(NULL)
, m_pHashForUpdates(NULL)
, m_pUpdates0List(NULL)
, m_pUpdatesNegList(NULL)
, m_pUpdatesPosList(NULL)
{
assert(pSharedScheduler == NULL);
}

View File

@ -194,7 +194,7 @@ CCActionInterval *CCSpeed::reverse()
//
CCFollow::~CCFollow()
{
m_pobFollowedNode->release();
CC_SAFE_RELEASE(m_pobFollowedNode);
}
CCFollow *CCFollow::actionWithTarget(CCNode *pFollowedNode)

View File

@ -32,9 +32,7 @@ namespace cocos2d {
// InstantAction
//
CCActionInstant::CCActionInstant()
{
m_fDuration = 0;
}
{}
CCObject * CCActionInstant::copyWithZone(cocos2d::CCZone *pZone)
{
@ -412,13 +410,13 @@ namespace cocos2d {
// CCCallFuncO
//
CCCallFuncO::CCCallFuncO()
: m_pObject(NULL)
{
m_pTarget = NULL;
}
CCCallFuncO::~CCCallFuncO()
{
m_pTarget->release();
CC_SAFE_RELEASE(m_pObject);
}
void CCCallFuncO::execute()

View File

@ -225,8 +225,8 @@ CCObject* CCSequence::copyWithZone(CCZone *pZone)
CCSequence::~CCSequence(void)
{
m_pActions[0]->release();
m_pActions[1]->release();
CC_SAFE_RELEASE(m_pActions[0]);
CC_SAFE_RELEASE(m_pActions[1]);
}
void CCSequence::startWithTarget(CCNode *pTarget)
@ -356,7 +356,7 @@ CCObject* CCRepeat::copyWithZone(cocos2d::CCZone *pZone)
CCRepeat::~CCRepeat(void)
{
m_pOther->release();
CC_SAFE_RELEASE(m_pOther);
}
void CCRepeat::startWithTarget(CCNode *pTarget)
@ -429,7 +429,7 @@ CCActionInterval* CCRepeat::reverse(void)
//
CCRepeatForever::~CCRepeatForever()
{
m_pOther->release();
CC_SAFE_RELEASE(m_pOther);
}
CCRepeatForever *CCRepeatForever::actionWithAction(CCActionInterval *pAction)
{
@ -591,8 +591,8 @@ CCObject* CCSpawn::copyWithZone(cocos2d::CCZone *pZone)
CCSpawn::~CCSpawn(void)
{
m_pOne->release();
m_pTwo->release();
CC_SAFE_RELEASE(m_pOne);
CC_SAFE_RELEASE(m_pTwo);
}
void CCSpawn::startWithTarget(CCNode *pTarget)
@ -1769,7 +1769,7 @@ CCObject* CCReverseTime::copyWithZone(cocos2d::CCZone *pZone)
CCReverseTime::~CCReverseTime(void)
{
m_pOther->release();
CC_SAFE_RELEASE(m_pOther);
}
void CCReverseTime::startWithTarget(CCNode *pTarget)

View File

@ -84,6 +84,9 @@ void CCActionManager::selectorProtocolRelease()
}
CCActionManager::CCActionManager(void)
: m_pCurrentTarget(NULL),
m_pTargets(NULL),
m_bCurrentTargetSalvaged(false)
{
assert(gSharedManager == NULL);
}

View File

@ -288,15 +288,8 @@ namespace cocos2d
CCShuffleTiles::~CCShuffleTiles(void)
{
if (m_pTilesOrder)
{
delete[] m_pTilesOrder;
}
if (m_pTiles)
{
delete[] m_pTiles;
}
CC_SAFE_DELETE_ARRAY(m_pTilesOrder);
CC_SAFE_DELETE_ARRAY(m_pTiles);
}
void CCShuffleTiles::shuffle(int *pArray, int nLen)
@ -662,10 +655,7 @@ namespace cocos2d
CCTurnOffTiles::~CCTurnOffTiles(void)
{
if (m_pTilesOrder)
{
delete[] m_pTilesOrder;
}
CC_SAFE_DELETE_ARRAY(m_pTilesOrder);
}
void CCTurnOffTiles::shuffle(int *pArray, int nLen)

View File

@ -33,12 +33,19 @@ namespace cocos2d {
// CCAtlasNode - Creation & Init
CCAtlasNode::CCAtlasNode()
: m_pTextureAtlas(NULL)
, m_bIsOpacityModifyRGB(false)
, m_nItemWidth(0)
, m_nItemHeight(0)
, m_cOpacity(0)
, m_nItemsPerRow(0)
, m_nItemsPerColumn(0)
{
}
CCAtlasNode::~CCAtlasNode()
{
m_pTextureAtlas->release();
CC_SAFE_RELEASE(m_pTextureAtlas);
}
CCAtlasNode * CCAtlasNode::atlasWithTileFile(const char *tile, int tileWidth, int tileHeight, int itemsToRender)

View File

@ -35,7 +35,7 @@ CCAutoreleasePool::CCAutoreleasePool(void)
CCAutoreleasePool::~CCAutoreleasePool(void)
{
delete m_pManagedObjectArray;
CC_SAFE_DELETE(m_pManagedObjectArray);
}
void CCAutoreleasePool::addObject(CCObject* pObject)
@ -105,7 +105,7 @@ CCPoolManager::~CCPoolManager()
m_pCurReleasePool = NULL;
m_pReleasePoolStack->removeObjectAtIndex(0);
delete m_pReleasePoolStack;
CC_SAFE_DELETE(m_pReleasePoolStack);
}
void CCPoolManager::finalize()

View File

@ -32,16 +32,13 @@ using namespace std;
namespace cocos2d {
CCData::CCData(void)
: m_pData(NULL)
{
m_pData = NULL;
}
CCData::~CCData(void)
{
if (m_pData)
{
delete[] m_pData;
}
CC_SAFE_DELETE_ARRAY(m_pData);
}
CCData* CCData::dataWithContentsOfFile(const string &strPath)

View File

@ -40,11 +40,7 @@ CCSet::CCSet(const CCSet &rSetObject)
CCSet::~CCSet(void)
{
if (m_pSet)
{
delete m_pSet;
m_pSet = NULL;
}
CC_SAFE_DELETE(m_pSet);
}
CCSet* CCSet::copy(void)

View File

@ -30,10 +30,9 @@ THE SOFTWARE.
namespace cocos2d
{
CCGrabber::CCGrabber(void)
: m_fbo(0)
, m_oldFBO(0)
{
m_fbo = 0;
m_oldFBO = 0;
// generate FBO
ccglGenFramebuffers(1, &m_fbo);
}

View File

@ -38,9 +38,12 @@ namespace cocos2d {
}
CCKeyboardEventHandle::~CCKeyboardEventHandle()
{
if (m_pDelegate)
{
m_pDelegate->KeyboardDestroy();
}
}
void CCKeyboardEventHandle::setDelegate(CCKeyboardEventDelegate *pDelegate)
{

View File

@ -38,9 +38,12 @@ namespace cocos2d {
}
CCMouseEventHandle::~CCMouseEventHandle()
{
if (m_pDelegate)
{
m_pDelegate->MouseDestroy();
}
}
void CCMouseEventHandle::setDelegate(CCMouseEventDelegate *pDelegate)
{

View File

@ -119,7 +119,9 @@ protected:
class CC_DLL CCFiniteTimeAction : public CCAction
{
public:
CCFiniteTimeAction(){}
CCFiniteTimeAction()
: m_fDuration(0)
{}
virtual ~CCFiniteTimeAction(){}
//! get duration in seconds of the action
inline ccTime getDuration(void) { return m_fDuration; }
@ -145,7 +147,10 @@ class CCRepeatForever;
class CC_DLL CCSpeed : public CCAction
{
public:
CCSpeed(){}
CCSpeed()
: m_fSpeed(0.0)
, m_pOther(NULL)
{}
virtual ~CCSpeed(void);
inline float getSpeed(void) { return m_fSpeed; }
@ -187,7 +192,15 @@ Instead of using CCCamera as a "follower", use this action instead.
class CC_DLL CCFollow : public CCAction
{
public:
CCFollow(){}
CCFollow()
: m_pobFollowedNode(NULL)
, m_bBoundaryFullyCovered(false)
, m_bBoundarySet(false)
, m_fBottomBoundary(0.0)
, m_fLeftBoundary(0.0)
, m_fRightBoundary(0.0)
, m_fTopBoundary(0.0)
{}
virtual ~CCFollow(void);
inline bool isBoundarySet(void) { return m_bBoundarySet; }

View File

@ -72,7 +72,18 @@ namespace cocos2d {
class CC_DLL CCOrbitCamera : public CCActionCamera //<NSCopying>
{
public:
CCOrbitCamera(){}
CCOrbitCamera()
: m_fAngleX(0.0)
, m_fAngleZ(0.0)
, m_fDeltaAngleX(0.0)
, m_fDeltaAngleZ(0.0)
, m_fDeltaRadius(0.0)
, m_fRadDeltaX(0.0)
, m_fRadDeltaZ(0.0)
, m_fRadius(0.0)
, m_fRadX(0.0)
, m_fRadZ(0.0)
{}
~CCOrbitCamera(){}
/** 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);

View File

@ -104,7 +104,9 @@ namespace cocos2d {
class CC_DLL CCFlipX : public CCActionInstant
{
public:
CCFlipX(){}
CCFlipX()
:m_bFlipX(false)
{}
virtual ~CCFlipX(){}
/** create the action */
@ -127,7 +129,9 @@ namespace cocos2d {
class CC_DLL CCFlipY : public CCActionInstant
{
public:
CCFlipY(){}
CCFlipY()
:m_bFlipY(false)
{}
virtual ~CCFlipY(){}
/** create the action */
@ -167,9 +171,9 @@ namespace cocos2d {
{
public:
CCCallFunc()
: m_pCallFunc(NULL)
, m_pSelectorTarget(NULL)
{
m_pCallFunc = NULL;
m_pSelectorTarget = NULL;
}
virtual ~CCCallFunc()
{

View File

@ -146,7 +146,9 @@ To repeat the an action for a limited number of times use the Repeat action.
class CC_DLL CCRepeatForever : public CCActionInterval
{
public:
CCRepeatForever(){}
CCRepeatForever()
: m_pOther(NULL)
{}
virtual ~CCRepeatForever();
/** initializes the action */

View File

@ -578,7 +578,9 @@ protected:
class CCDisplayLinkDirector : public CCDirector
{
public:
CCDisplayLinkDirector(void) {}
CCDisplayLinkDirector(void)
: m_bInvalid(false)
{}
virtual void mainLoop(void);
virtual void setAnimationInterval(double dValue);

View File

@ -86,6 +86,7 @@ namespace cocos2d{
public:
CCBMFontConfiguration()
: m_pKerningDictionary(NULL)
, m_uCommonHeight(0)
{}
virtual ~CCBMFontConfiguration();
char * description();
@ -148,6 +149,9 @@ namespace cocos2d{
public:
CCLabelBMFont()
: m_pConfiguration(NULL)
, m_bIsOpacityModifyRGB(false)
, m_cOpacity(0)
, m_sString("")
{}
virtual ~CCLabelBMFont();
/** Purges the cached data.

View File

@ -50,7 +50,10 @@ namespace cocos2d{
class CC_DLL CCMenu : public CCLayer, public CCRGBAProtocol
{
public:
CCMenu(){}
CCMenu()
: m_cOpacity(0)
, m_pSelectedItem(NULL)
{}
virtual ~CCMenu(){}
/** creates a CCMenu with it's items */
static CCMenu* menuWithItems(CCMenuItem* item, ...);

View File

@ -52,6 +52,9 @@ namespace cocos2d{
public:
CCMenuItem()
: m_pListener(NULL)
, m_bIsEnabled(false)
, m_bIsSelected(false)
, m_pfnSelector(NULL)
{}
virtual ~CCMenuItem(){}
/** Creates a CCMenuItem with a target/selector */
@ -87,6 +90,7 @@ namespace cocos2d{
public:
CCMenuItemLabel()
: m_pLabel(NULL)
, m_fOriginalScale(0.0)
{}
virtual ~CCMenuItemLabel();
/** creates a CCMenuItemLabel with a Label, target and selector */
@ -247,7 +251,11 @@ namespace cocos2d{
*/
CC_PROPERTY(CCMutableArray<CCMenuItem*>*, m_pSubItems, SubItems);
public:
CCMenuItemToggle(){}
CCMenuItemToggle()
: m_cOpacity(0)
, m_pSubItems(NULL)
, m_uSelectedIndex(0)
{}
virtual ~CCMenuItemToggle();
/** creates a menu item from a list of items with a target/selector */
static CCMenuItemToggle* itemWithTarget(SelectorProtocol* target, SEL_MenuHandler selector, CCMenuItem* item, ...);

View File

@ -56,7 +56,12 @@ class CC_DLL CCMotionStreak : public CCNode, public CCTextureProtocol
CC_PROPERTY(CCTexture2D*, m_pTexture, Texture)
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc)
public:
CCMotionStreak(){}
CCMotionStreak()
: m_fSegThreshold(0.0)
, m_fWidth(0.0)
, m_pRibbon(NULL)
, m_pTexture(NULL)
{}
virtual ~CCMotionStreak(){}
/** creates the a MotionStreak. The image will be loaded using the TextureMgr. */
static CCMotionStreak * streakWithFade(float fade, float seg, const char *imagePath, float width, float length, ccColor4B color);

View File

@ -106,7 +106,11 @@ public:
unsigned int m_uEnd;
unsigned int m_uBegin;
public:
CCRibbonSegment(){}
CCRibbonSegment()
: m_bFinished(false)
, m_uBegin(0)
, m_uEnd(0)
{}
virtual ~CCRibbonSegment();
char * description();
bool init();

View File

@ -131,7 +131,7 @@ public:
static void purgeSharedSpriteFrameCache(void);
private:
CCSpriteFrameCache(void) {}
CCSpriteFrameCache(void) : m_pSpriteFrames(NULL), m_pSpriteFramesAliases(NULL){}
const char * valueForKey(const char *key, CCDictionary<std::string, CCObject*> *dict);
protected:

View File

@ -95,7 +95,12 @@ class CC_DLL CCTouchDispatcher : public CCObject, public EGLTouchDelegate
public:
~CCTouchDispatcher();
bool init(void);
CCTouchDispatcher() {}
CCTouchDispatcher()
: m_pHandlersToAdd(NULL)
, m_pHandlersToRemove(NULL)
, m_pStandardHandlers(NULL)
, m_pTargetedHandlers(NULL)
{}
public:
/** Whether or not the events are going to be dispatched. Default: true */

View File

@ -38,9 +38,12 @@ CCKeypadDelegate* CCKeypadHandler::getDelegate()
}
CCKeypadHandler::~CCKeypadHandler()
{
if (m_pDelegate)
{
m_pDelegate->KeypadDestroy();
}
}
void CCKeypadHandler::setDelegate(CCKeypadDelegate *pDelegate)
{

View File

@ -46,10 +46,17 @@ CCKeypadDispatcher::CCKeypadDispatcher()
CCKeypadDispatcher::~CCKeypadDispatcher()
{
m_pDelegates->release();
CC_SAFE_RELEASE(m_pDelegates);
if (m_pHandlersToAdd)
{
ccCArrayFree(m_pHandlersToAdd);
}
if (m_pHandlersToRemove)
{
ccCArrayFree(m_pHandlersToRemove);
}
}
CCKeypadDispatcher* CCKeypadDispatcher::sharedDispatcher()
{

View File

@ -412,7 +412,7 @@ namespace cocos2d{
CCLabelBMFont::~CCLabelBMFont()
{
m_sString.clear();
m_pConfiguration->release();
CC_SAFE_RELEASE(m_pConfiguration);
}
// BitmapFontAtlas - Atlas generation

View File

@ -31,23 +31,15 @@ namespace cocos2d{
CCLabelTTF::CCLabelTTF()
: m_pFontName(NULL)
, m_pString(NULL)
, m_fFontSize(0.0)
, m_eAlignment(CCTextAlignmentCenter)
{
}
CCLabelTTF::~CCLabelTTF()
{
if (m_pFontName)
{
delete m_pFontName;
m_pFontName = NULL;
}
if (m_pString)
{
delete m_pString;
m_pString = NULL;
}
CC_SAFE_DELETE(m_pFontName);
CC_SAFE_DELETE(m_pString);
}
CCLabelTTF * CCLabelTTF::labelWithString(const char *label, CCSize dimensions, CCTextAlignment alignment, const char *fontName, float fontSize)

View File

@ -577,7 +577,7 @@ namespace cocos2d{
}
CCMenuItemToggle::~CCMenuItemToggle()
{
m_pSubItems->release();
CC_SAFE_RELEASE(m_pSubItems);
}
void CCMenuItemToggle::setSelectedIndex(unsigned int index)
{

View File

@ -88,12 +88,8 @@ bool CCProgressTimer::initWithTexture(cocos2d::CCTexture2D *pTexture)
CCProgressTimer::~CCProgressTimer(void)
{
if (m_pVertexData)
{
delete[] m_pVertexData;
}
m_pSprite->release();
CC_SAFE_DELETE_ARRAY(m_pVertexData);
CC_SAFE_RELEASE(m_pSprite);
}
void CCProgressTimer::setPercentage(float fPercentage)

View File

@ -60,17 +60,18 @@ public:
public:
CCDictMaker()
: m_pRootDict(NULL),
m_pCurDict(NULL),
m_tState(SAX_NONE),
m_pArray(NULL),
m_bInArray(false)
{
m_pRootDict = NULL;
m_pCurDict = NULL;
m_tState = SAX_NONE;
m_pArray = NULL;
m_bInArray = false;
}
~CCDictMaker()
{
}
CCDictionary<std::string, CCObject*> *dictionaryWithContentsOfFile(const char *pFileName)
{
CCSAXParser parser;

View File

@ -326,10 +326,10 @@ namespace cocos2d
CCGrid3D::~CCGrid3D(void)
{
free(m_pTexCoordinates);
free(m_pVertices);
free(m_pIndices);
free(m_pOriginalVertices);
CC_SAFE_FREE(m_pTexCoordinates);
CC_SAFE_FREE(m_pVertices);
CC_SAFE_FREE(m_pIndices);
CC_SAFE_FREE(m_pOriginalVertices);
}
void CCGrid3D::blit(void)
@ -461,10 +461,10 @@ namespace cocos2d
CCTiledGrid3D::~CCTiledGrid3D(void)
{
free(m_pTexCoordinates);
free(m_pVertices);
free(m_pOriginalVertices);
free(m_pIndices);
CC_SAFE_FREE(m_pTexCoordinates);
CC_SAFE_FREE(m_pVertices);
CC_SAFE_FREE(m_pOriginalVertices);
CC_SAFE_FREE(m_pIndices);
}
CCTiledGrid3D* CCTiledGrid3D::gridWithSize(cocos2d::ccGridSize gridSize, cocos2d::CCTexture2D *pTexture, bool bFlipped)

View File

@ -303,6 +303,7 @@ bool CCLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
CCLayerColor::CCLayerColor()
: m_cOpacity(0)
{
}
CCLayerColor::~CCLayerColor()
@ -619,11 +620,13 @@ CCPoint CCLayerGradient::getVector()
/// MultiplexLayer
CCMultiplexLayer::CCMultiplexLayer()
: m_nEnabledLayer(0)
, m_pLayers(NULL)
{
}
CCMultiplexLayer::~CCMultiplexLayer()
{
m_pLayers->release();
CC_SAFE_RELEASE(m_pLayers);
}
CCMultiplexLayer * CCMultiplexLayer::layerWithLayers(CCLayer * layer, ...)

View File

@ -61,7 +61,7 @@ namespace cocos2d
CCAnimationCache::~CCAnimationCache()
{
CCLOGINFO("cocos2d: deallocing %p", this);
m_pAnimations->release();
CC_SAFE_RELEASE(m_pAnimations);
}
void CCAnimationCache::addAnimation(CCAnimation *animation, const char * name)

View File

@ -127,8 +127,8 @@ namespace cocos2d
CCSpriteBatchNode::~CCSpriteBatchNode()
{
m_pobTextureAtlas->release();
m_pobDescendants->release();
CC_SAFE_RELEASE(m_pobTextureAtlas);
CC_SAFE_RELEASE(m_pobDescendants);
}
// override visit

View File

@ -64,8 +64,8 @@ bool CCSpriteFrameCache::init(void)
CCSpriteFrameCache::~CCSpriteFrameCache(void)
{
m_pSpriteFrames->release();
m_pSpriteFramesAliases->release();
CC_SAFE_RELEASE(m_pSpriteFrames);
CC_SAFE_RELEASE(m_pSpriteFramesAliases);
}
void CCSpriteFrameCache::addSpriteFramesWithDictionary(CCDictionary<std::string, CCObject*> *dictionary, CCTexture2D *pobTexture)

View File

@ -179,8 +179,13 @@ namespace cocos2d {
static CCTexture2DPixelFormat g_defaultAlphaPixelFormat = kCCTexture2DPixelFormat_Default;
CCTexture2D::CCTexture2D()
: m_uName(0)
, m_bHasPremultipliedAlpha(false)
, m_fMaxS(0.0)
, m_fMaxT(0.0)
, m_uPixelsHigh(0)
, m_uPixelsWide(0)
{
m_uName = 0;
}
CCTexture2D::~CCTexture2D()

View File

@ -113,11 +113,7 @@ namespace cocos2d {
m_pAtlasIndexArray = NULL;
}
if( m_pTiles )
{
delete [] m_pTiles;
m_pTiles = NULL;
}
CC_SAFE_DELETE_ARRAY(m_pTiles);
}
CCTMXTilesetInfo * CCTMXLayer::getTileSet()
{

View File

@ -93,14 +93,11 @@ bool CCTouchDispatcher::init(void)
CCTouchDispatcher::~CCTouchDispatcher(void)
{
m_pTargetedHandlers->release();
m_pStandardHandlers->release();
m_pHandlersToAdd->release();
ccCArrayFree(m_pHandlersToRemove);
CC_SAFE_RELEASE(m_pTargetedHandlers);
CC_SAFE_RELEASE(m_pStandardHandlers);
CC_SAFE_RELEASE(m_pHandlersToAdd);
m_pTargetedHandlers = NULL;
m_pStandardHandlers = NULL;
m_pHandlersToAdd = NULL;
ccCArrayFree(m_pHandlersToRemove);
m_pHandlersToRemove = NULL;
}

View File

@ -98,9 +98,12 @@ bool CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
}
CCTouchHandler::~CCTouchHandler(void)
{
if (m_pDelegate)
{
m_pDelegate->destroy();
}
}
// implementation of CCStandardTouchHandler
bool CCStandardTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority)
@ -204,6 +207,6 @@ bool CCTargetedTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nP
CCTargetedTouchHandler::~CCTargetedTouchHandler(void)
{
m_pClaimedTouches->release();
CC_SAFE_RELEASE(m_pClaimedTouches);
}
}//namespace cocos2d