From d020114e5937a2f01e4529599de1eaf6eead8d4d Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 23 Jan 2016 22:00:51 +1300 Subject: [PATCH 1/4] Make entity properties return undefined value after entity is deleted --- libraries/entities/src/EntityItemProperties.cpp | 9 ++++++++- libraries/entities/src/EntityItemProperties.h | 4 ++++ libraries/entities/src/EntityScriptingInterface.cpp | 4 +++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 1807a45cc7..c8bafd0619 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -47,7 +47,9 @@ _localRenderAlphaChanged(false), _defaultSettings(true), _naturalDimensions(1.0f, 1.0f, 1.0f), _naturalPosition(0.0f, 0.0f, 0.0f), -_desiredProperties(desiredProperties) +_desiredProperties(desiredProperties), + +_entityFound(false) { } @@ -321,6 +323,11 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine, bool QScriptValue properties = engine->newObject(); EntityItemProperties defaultEntityProperties; + if (!_entityFound) { + // Return without setting any default property values so that properties are reported in JavaScript as undefined. + return properties; + } + if (_idSet) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER_ALWAYS(id, _id.toString()); } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index ff288fbe95..7c7dd4d747 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -272,6 +272,8 @@ public: void setJointRotationsDirty() { _jointRotationsSetChanged = true; _jointRotationsChanged = true; } void setJointTranslationsDirty() { _jointTranslationsSetChanged = true; _jointTranslationsChanged = true; } + void setEntityFound() { _entityFound = true; } + protected: QString getCollisionMaskAsString() const; void setCollisionMaskFromString(const QString& maskString); @@ -283,6 +285,8 @@ private: EntityTypes::EntityType _type; void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } + bool _entityFound; + float _glowLevel; float _localRenderAlpha; bool _glowLevelChanged; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8fd7be912e..5bee9ac3d8 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -202,11 +202,13 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(QUuid identit } } + results = convertLocationToScriptSemantics(results); + results.setEntityFound(); } }); } - return convertLocationToScriptSemantics(results); + return results; } QUuid EntityScriptingInterface::editEntity(QUuid id, const EntityItemProperties& scriptSideProperties) { From 9429f48a7cd2b7a87a49bbb341891f449f6f2617 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 23 Jan 2016 22:05:46 +1300 Subject: [PATCH 2/4] Remove erroneous edit.js call with missing entity ID JavaScript exception was being thrown now that entity properties are undefined if entity is not found. --- examples/libraries/entitySelectionTool.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/libraries/entitySelectionTool.js b/examples/libraries/entitySelectionTool.js index 94ffb48a71..c1675ef044 100644 --- a/examples/libraries/entitySelectionTool.js +++ b/examples/libraries/entitySelectionTool.js @@ -1515,7 +1515,6 @@ SelectionDisplay = (function() { } that.updateRotationHandles(); - that.highlightSelectable(); var rotation, dimensions, position, registrationPoint; From 840bf7cfb4c3d239df05ca8dc6c50fa8a722bd42 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sun, 24 Jan 2016 10:53:40 +1300 Subject: [PATCH 3/4] Fix OSX and Linux build warning And a typo noticed in passing. --- libraries/entities/src/EntityItemProperties.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index 7c7dd4d747..c0a610ac5c 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -285,14 +285,12 @@ private: EntityTypes::EntityType _type; void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } - bool _entityFound; - float _glowLevel; float _localRenderAlpha; bool _glowLevelChanged; bool _localRenderAlphaChanged; bool _defaultSettings; - bool _dimensionsInitialized = true; // Only false if creating an entity localy with no dimensions properties + bool _dimensionsInitialized = true; // Only false if creating an entity locally with no dimensions properties // NOTE: The following are pseudo client only properties. They are only used in clients which can access // properties of model geometry. But these properties are not serialized like other properties. @@ -302,6 +300,8 @@ private: glm::vec3 _naturalPosition; EntityPropertyFlags _desiredProperties; // if set will narrow scopes of copy/to/from to just these properties + + bool _entityFound; }; Q_DECLARE_METATYPE(EntityItemProperties); From 8a8e14f54a027a72cb17d45af2c6e67c4650337e Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 25 Jan 2016 11:22:31 +1300 Subject: [PATCH 4/4] Rework initializers --- .../entities/src/EntityItemProperties.cpp | 19 +------------- libraries/entities/src/EntityItemProperties.h | 26 +++++++++---------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index c8bafd0619..7069b983bc 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -32,24 +32,7 @@ KeyLightPropertyGroup EntityItemProperties::_staticKeyLight; EntityPropertyList PROP_LAST_ITEM = (EntityPropertyList)(PROP_AFTER_LAST_ITEM - 1); EntityItemProperties::EntityItemProperties(EntityPropertyFlags desiredProperties) : - -_id(UNKNOWN_ENTITY_ID), -_idSet(false), -_lastEdited(0), -_type(EntityTypes::Unknown), - -_glowLevel(0.0f), -_localRenderAlpha(1.0f), - -_glowLevelChanged(false), -_localRenderAlphaChanged(false), - -_defaultSettings(true), -_naturalDimensions(1.0f, 1.0f, 1.0f), -_naturalPosition(0.0f, 0.0f, 0.0f), -_desiredProperties(desiredProperties), - -_entityFound(false) + _desiredProperties(desiredProperties) //, { } diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index c0a610ac5c..f66d17eae2 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -279,29 +279,29 @@ protected: void setCollisionMaskFromString(const QString& maskString); private: - QUuid _id; - bool _idSet; - quint64 _lastEdited; - EntityTypes::EntityType _type; + QUuid _id { UNKNOWN_ENTITY_ID }; + bool _idSet { false }; + quint64 _lastEdited { 0 }; + EntityTypes::EntityType _type { EntityTypes::Unknown }; void setType(const QString& typeName) { _type = EntityTypes::getEntityTypeFromName(typeName); } - float _glowLevel; - float _localRenderAlpha; - bool _glowLevelChanged; - bool _localRenderAlphaChanged; - bool _defaultSettings; - bool _dimensionsInitialized = true; // Only false if creating an entity locally with no dimensions properties + float _glowLevel { 0.0f }; + float _localRenderAlpha { 1.0f }; + bool _glowLevelChanged { false }; + bool _localRenderAlphaChanged { false }; + bool _defaultSettings { true }; + bool _dimensionsInitialized { true }; // Only false if creating an entity locally with no dimensions properties // NOTE: The following are pseudo client only properties. They are only used in clients which can access // properties of model geometry. But these properties are not serialized like other properties. QVector _sittingPoints; QStringList _textureNames; - glm::vec3 _naturalDimensions; - glm::vec3 _naturalPosition; + glm::vec3 _naturalDimensions { 1.0f, 1.0f, 1.0f }; + glm::vec3 _naturalPosition { 0.0f, 0.0f, 0.0f }; EntityPropertyFlags _desiredProperties; // if set will narrow scopes of copy/to/from to just these properties - bool _entityFound; + bool _entityFound { false }; }; Q_DECLARE_METATYPE(EntityItemProperties);