diff --git a/cocos2d/core/base-ui/CCWidgetManager.js b/cocos2d/core/base-ui/CCWidgetManager.js index e9ce8e78e0..79077bd0e1 100644 --- a/cocos2d/core/base-ui/CCWidgetManager.js +++ b/cocos2d/core/base-ui/CCWidgetManager.js @@ -274,8 +274,10 @@ function refreshScene () { if (nowPreviewing) { animationState.animatedSinceLastFrame = true; let component = cc.engine.getInstanceById(AnimUtils.Cache.component); - let animation = component.getAnimationState(AnimUtils.Cache.animation); - animationState.time = animation.time; + if (component) { + let animation = component.getAnimationState(AnimUtils.Cache.animation); + animationState.time = animation.time; + } } else { animationState.animatedSinceLastFrame = false; @@ -283,10 +285,12 @@ function refreshScene () { } else if (nowPreviewing) { let component = cc.engine.getInstanceById(AnimUtils.Cache.component); - let animation = component.getAnimationState(AnimUtils.Cache.animation); - if (animationState.time !== animation.time) { - animationState.animatedSinceLastFrame = true; - animationState.time = AnimUtils.Cache.animation.time; + if (component) { + let animation = component.getAnimationState(AnimUtils.Cache.animation); + if (animationState.time !== animation.time) { + animationState.animatedSinceLastFrame = true; + animationState.time = AnimUtils.Cache.animation.time; + } } } } @@ -307,18 +311,20 @@ function refreshScene () { (AnimUtils = Editor.require('scene://utils/animation')) && AnimUtils.Cache.animation) { var editingNode = cc.engine.getInstanceById(AnimUtils.Cache.rNode); - for (i = activeWidgets.length - 1; i >= 0; i--) { - widget = activeWidgets[i]; - var node = widget.node; - if (widget.alignMode !== AlignMode.ALWAYS && - animationState.animatedSinceLastFrame && - node.isChildOf(editingNode) - ) { - // widget contains in activeWidgets should aligned at least once - widget.enabled = false; - } - else { - align(node, widget); + if (editingNode) { + for (i = activeWidgets.length - 1; i >= 0; i--) { + widget = activeWidgets[i]; + var node = widget.node; + if (widget.alignMode !== AlignMode.ALWAYS && + animationState.animatedSinceLastFrame && + node.isChildOf(editingNode) + ) { + // widget contains in activeWidgets should aligned at least once + widget.enabled = false; + } + else { + align(node, widget); + } } } }