diff --git a/cocos2dx/base_nodes/CCNode.cpp b/cocos2dx/base_nodes/CCNode.cpp index b4787c2367..830c0779fe 100644 --- a/cocos2dx/base_nodes/CCNode.cpp +++ b/cocos2dx/base_nodes/CCNode.cpp @@ -489,6 +489,8 @@ void CCNode::setGLServerState(ccGLServerState glServerState) void CCNode::setUserObject(CCObject *pUserObject) { + CC_SAFE_RELEASE(m_pUserObject); + CC_SAFE_RETAIN(pUserObject); m_pUserObject = pUserObject; } diff --git a/cocos2dx/base_nodes/CCNode.h b/cocos2dx/base_nodes/CCNode.h index 40478a688e..2809257d4f 100644 --- a/cocos2dx/base_nodes/CCNode.h +++ b/cocos2dx/base_nodes/CCNode.h @@ -276,7 +276,7 @@ public: /** Similar to userData, but instead of holding a void* it holds an id */ virtual CCObject* getUserObject(); - virtual void setUserObject(CCObject *pUserObject); + virtual void setUserObject(CCObject *pUserObject); //retain /** Shader Program @since v2.0 diff --git a/cocos2dx/cocoa/CCArray.h b/cocos2dx/cocoa/CCArray.h index 827bbda49c..1f68f08351 100644 --- a/cocos2dx/cocoa/CCArray.h +++ b/cocos2dx/cocoa/CCArray.h @@ -48,25 +48,25 @@ __arr__++) I found that it's not work in C++. So it keep what it's look like in version 1.0.0-rc3. ---By Bin */ -#define CCARRAY_FOREACH(__array__, __object__) \ - if ((__array__) && (__array__)->data->num > 0) \ - for(CCObject** arr = (__array__)->data->arr, **end = (__array__)->data->arr + (__array__)->data->num-1; \ - arr <= end && (((__object__) = *arr) != NULL/* || true*/); \ - arr++) +#define CCARRAY_FOREACH(__array__, __object__) \ + if ((__array__) && (__array__)->data->num > 0) \ + for(CCObject** __arr__ = (__array__)->data->arr, **__end__ = (__array__)->data->arr + (__array__)->data->num-1; \ + __arr__ <= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \ + __arr__++) -#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \ - if ((__array__) && (__array__)->data->num > 0) \ - for(CCObject** arr = (__array__)->data->arr + (__array__)->data->num-1, **end = (__array__)->data->arr; \ - arr >= end && (((__object__) = *arr) != NULL/* || true*/); \ - arr--) +#define CCARRAY_FOREACH_REVERSE(__array__, __object__) \ + if ((__array__) && (__array__)->data->num > 0) \ + for(CCObject** __arr__ = (__array__)->data->arr + (__array__)->data->num-1, **__end__ = (__array__)->data->arr; \ + __arr__ >= __end__ && (((__object__) = *__arr__) != NULL/* || true*/); \ + __arr__--) #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) -#define CCARRAY_VERIFY_TYPE(__array__, __type__) \ - do { \ - if ((__array__) && (__array__)->data->num > 0) \ - for(CCObject** arr = (__array__)->data->arr, \ - **end = (__array__)->data->arr + (__array__)->data->num-1; arr <= end; arr++) \ - CCAssert(dynamic_cast<__type__>(*arr), "element type is wrong!"); \ +#define CCARRAY_VERIFY_TYPE(__array__, __type__) \ + do { \ + if ((__array__) && (__array__)->data->num > 0) \ + for(CCObject** __arr__ = (__array__)->data->arr, \ + **__end__ = (__array__)->data->arr + (__array__)->data->num-1; __arr__ <= __end__; __arr__++) \ + CCAssert(dynamic_cast<__type__>(*__arr__), "element type is wrong!"); \ } while(false) #else #define CCARRAY_VERIFY_TYPE(__array__, __type__) void(0)