Skip to content

Commit 11e91aa

Browse files
committed
Merge pull request cocos2d#2254 from dingpinglv/Iss5924_ComponentBug
Added fault tolerance to cc.Node for cc.Component.
2 parents 5b5faa7 + c6c9ca2 commit 11e91aa

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cocos2d/core/base-nodes/CCNode.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,9 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
20212021
* @return {cc.Component} The component found
20222022
*/
20232023
getComponent: function (name) {
2024-
return this._componentContainer.getComponent(name);
2024+
if(this._componentContainer)
2025+
return this._componentContainer.getComponent(name);
2026+
return null;
20252027
},
20262028

20272029
/**
@@ -2030,7 +2032,8 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
20302032
* @param {cc.Component} component
20312033
*/
20322034
addComponent: function (component) {
2033-
this._componentContainer.add(component);
2035+
if(this._componentContainer)
2036+
this._componentContainer.add(component);
20342037
},
20352038

20362039
/**
@@ -2039,15 +2042,18 @@ cc.Node = cc.Class.extend(/** @lends cc.Node# */{
20392042
* @param {String|cc.Component} component
20402043
*/
20412044
removeComponent: function (component) {
2042-
return this._componentContainer.remove(component);
2045+
if(this._componentContainer)
2046+
return this._componentContainer.remove(component);
2047+
return false;
20432048
},
20442049

20452050
/**
20462051
* Removes all components of cc.Node, it called when cc.Node is exiting from stage.
20472052
* @function
20482053
*/
20492054
removeAllComponents: function () {
2050-
this._componentContainer.removeAll();
2055+
if(this._componentContainer)
2056+
this._componentContainer.removeAll();
20512057
},
20522058

20532059
grid: null,

0 commit comments

Comments
 (0)