Skip to content

Commit 2bb2e9f

Browse files
James Chenminggo
authored andcommitted
Reverts Node::cleanup changes in PR cocos2d#17836 which is merged in v3.16. (cocos2d#18565)
* Reverts Node::cleanup changes in PR cocos2d#17836. Reason please review the bug report: cocos2d#18104 * Adds comment for reverting code in Node::cleanup.
1 parent 7058b7c commit 2bb2e9f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

cocos/2d/CCNode.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,15 @@ void Node::cleanup()
217217
// timers
218218
this->unscheduleAllCallbacks();
219219

220-
_eventDispatcher->removeEventListenersForTarget(this);
220+
// NOTE: Although it was correct that removing event listeners associated with current node in Node::cleanup.
221+
// But it broke the compatibility to the versions before v3.16 .
222+
// User code may call `node->removeFromParent(true)` which will trigger node's cleanup method, when the node
223+
// is added to scene again, event listeners like EventListenerTouchOneByOne will be lost.
224+
// In fact, user's code should use `node->removeFromParent(false)` in order not to do a cleanup and just remove node
225+
// from its parent. For more discussion about why we revert this change is at https://github.com/cocos2d/cocos2d-x/issues/18104.
226+
// We need to consider more before we want to correct the old and wrong logic code.
227+
// For now, compatiblity is the most important for our users.
228+
// _eventDispatcher->removeEventListenersForTarget(this);
221229

222230
for( const auto &child: _children)
223231
child->cleanup();

0 commit comments

Comments
 (0)