From 4dd9b3d061849e12eb75d3477a922ed27970ae39 Mon Sep 17 00:00:00 2001 From: Matthew Amato Date: Wed, 4 Nov 2015 21:53:38 -0500 Subject: [PATCH] All Entity.parent to be set to undefined. This should have always worked, but we were missing a `defined` check. Reported via the [forum](https://groups.google.com/d/msg/cesium-dev/danz-dtw8Jg/Id6DBZwaEQAJ) --- CHANGES.md | 1 + Source/DataSources/Entity.js | 4 +++- Specs/DataSources/EntitySpec.js | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 304157ff1088..bb38bb9d8c51 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Change Log * Fixed an issue where the sun texture is not generated correctly on some mobile devices. [#3141](https://github.com/AnalyticalGraphicsInc/cesium/issues/3141) * Fixed a bug in the deprecated `jsonp` that prevented it from returning a promise. Its replacement, `loadJsonp`, was unaffected. * Fixed glTF implementation to read the version as a string as per the specification and to correctly handle backwards compatibility for axis-angle rotations in glTF 0.8 models. +* Fixed a bug that caused setting `Entity.parent` to `undefined` to throw an exception. [#3169](https://github.com/AnalyticalGraphicsInc/cesium/issues/3169) * Added `Model.maximumScale` and `ModelGraphics.maximumScale` properties, giving an upper limit for minimumPixelSize. ### 1.15 - 2015-11-02 diff --git a/Source/DataSources/Entity.js b/Source/DataSources/Entity.js index 960d7086c5d3..46d5e0634c78 100644 --- a/Source/DataSources/Entity.js +++ b/Source/DataSources/Entity.js @@ -297,7 +297,9 @@ define([ } this._parent = value; - value._children.push(this); + if (defined(value)) { + value._children.push(this); + } var isShowing = this.isShowing; diff --git a/Specs/DataSources/EntitySpec.js b/Specs/DataSources/EntitySpec.js index 93cffd620586..c4f187b6962d 100644 --- a/Specs/DataSources/EntitySpec.js +++ b/Specs/DataSources/EntitySpec.js @@ -459,4 +459,21 @@ defineSuite([ expect(entity.show).toBe(true); expect(entity.isShowing).toBe(false); }); + + it('isShowing works when removing parent.', function() { + var entity = new Entity(); + entity.parent = new Entity({ + show : false + }); + expect(entity.isShowing).toBe(false); + + var listener = jasmine.createSpy('listener'); + entity.definitionChanged.addEventListener(listener); + + entity.parent = undefined; + + expect(listener.calls.count()).toBe(2); + expect(listener.calls.argsFor(0)).toEqual([entity, 'isShowing', true, false]); + expect(entity.isShowing).toBe(true); + }); }); \ No newline at end of file