From c2666474477a99aceebfbe32521e20cd9e0bb0e7 Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 28 Mar 2014 14:05:38 +0800 Subject: [PATCH 1/2] ParticleSystem should also override `onExit` to unschedule update since in `onEnter`, it will be scheduled again. Otherwise, it'll trigger an assert. --- cocos/2d/CCParticleSystem.cpp | 6 ++++++ cocos/2d/CCParticleSystem.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCParticleSystem.cpp b/cocos/2d/CCParticleSystem.cpp index c6ce201f77..fbeb95842e 100644 --- a/cocos/2d/CCParticleSystem.cpp +++ b/cocos/2d/CCParticleSystem.cpp @@ -624,6 +624,12 @@ void ParticleSystem::onEnter() this->scheduleUpdateWithPriority(1); } +void ParticleSystem::onExit() +{ + this->unscheduleUpdate(); + Node::onExit(); +} + void ParticleSystem::stopSystem() { _isActive = false; diff --git a/cocos/2d/CCParticleSystem.h b/cocos/2d/CCParticleSystem.h index 31e25952d3..9cd9823b70 100644 --- a/cocos/2d/CCParticleSystem.h +++ b/cocos/2d/CCParticleSystem.h @@ -191,7 +191,6 @@ public: //! whether or not the system is full bool isFull(); - virtual void onEnter(); //! should be overridden by subclasses virtual void updateQuadWithParticle(tParticle* particle, const Point& newPosition); //! should be overridden by subclasses @@ -355,6 +354,8 @@ public: inline void setPositionType(PositionType type) { _positionType = type; }; // Overrides + virtual void onEnter() override; + virtual void onExit() override; virtual void update(float dt) override; virtual Texture2D* getTexture() const override; virtual void setTexture(Texture2D *texture) override; From e87f6991cf06a3a2c3007c6a376078fd540e8cde Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 28 Mar 2014 14:09:51 +0800 Subject: [PATCH 2/2] User object has to be released before others, since userObject may have a weak reference of this node. It may invoke `node->stopAllAction();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`. --- cocos/2d/CCNode.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index b739b58074..848597b048 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -154,6 +154,10 @@ Node::~Node() } #endif + // User object has to be released before others, since userObject may have a weak reference of this node + // It may invoke `node->stopAllAction();` while `_actionManager` is null if the next line is after `CC_SAFE_RELEASE_NULL(_actionManager)`. + CC_SAFE_RELEASE_NULL(_userObject); + CC_SAFE_RELEASE_NULL(_actionManager); CC_SAFE_RELEASE_NULL(_scheduler); @@ -162,7 +166,6 @@ Node::~Node() // attributes CC_SAFE_RELEASE_NULL(_shaderProgram); - CC_SAFE_RELEASE_NULL(_userObject); for (auto& child : _children) {