From 15394056ebdfa7871fa4ad22d990bb4cf04d079b Mon Sep 17 00:00:00 2001 From: humbletim Date: Fri, 20 Jan 2017 22:27:43 -0500 Subject: [PATCH 1/6] * add isInEditMode to utils.js * update grab.js to use the latest Settings edit mode detection approach * add edit guards to handControllerGrab.js and grab.js * update edit.js to consistently initialize Setting's edit flag --- scripts/system/controllers/grab.js | 25 +------------------ .../system/controllers/handControllerGrab.js | 7 +++--- scripts/system/edit.js | 3 +-- scripts/system/libraries/utils.js | 6 +++++ 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/scripts/system/controllers/grab.js b/scripts/system/controllers/grab.js index 3ce44c2672..38a07c469d 100644 --- a/scripts/system/controllers/grab.js +++ b/scripts/system/controllers/grab.js @@ -45,8 +45,6 @@ var DEFAULT_GRABBABLE_DATA = { var ACTION_TTL = 10; // seconds -var enabled = true; - function getTag() { return "grab-" + MyAvatar.sessionUUID; } @@ -321,7 +319,7 @@ Grabber.prototype.computeNewGrabPlane = function() { } Grabber.prototype.pressEvent = function(event) { - if (!enabled) { + if (isInEditMode()) { return; } @@ -633,31 +631,10 @@ function keyReleaseEvent(event) { grabber.keyReleaseEvent(event); } -function editEvent(channel, message, sender, localOnly) { - if (channel != "edit-events") { - return; - } - if (sender != MyAvatar.sessionUUID) { - return; - } - if (!localOnly) { - return; - } - try { - var data = JSON.parse(message); - if ("enabled" in data) { - enabled = !data["enabled"]; - } - } catch(e) { - } -} - Controller.mousePressEvent.connect(pressEvent); Controller.mouseMoveEvent.connect(moveEvent); Controller.mouseReleaseEvent.connect(releaseEvent); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); -Messages.subscribe("edit-events"); -Messages.messageReceived.connect(editEvent); }()); // END LOCAL_SCOPE diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 57698bd0dc..51dd40fe4d 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -493,11 +493,9 @@ function removeMyAvatarFromCollidesWith(origCollidesWith) { // If another script is managing the reticle (as is done by HandControllerPointer), we should not be setting it here, // and we should not be showing lasers when someone else is using the Reticle to indicate a 2D minor mode. var EXTERNALLY_MANAGED_2D_MINOR_MODE = true; -var EDIT_SETTING = "io.highfidelity.isEditting"; function isEditing() { - var actualSettingValue = Settings.getValue(EDIT_SETTING) === "false" ? false : !!Settings.getValue(EDIT_SETTING); - return EXTERNALLY_MANAGED_2D_MINOR_MODE && actualSettingValue; + return EXTERNALLY_MANAGED_2D_MINOR_MODE && isInEditMode(); } function isIn2DMode() { @@ -844,6 +842,9 @@ function MyController(hand) { }; this.callEntityMethodOnGrabbed = function(entityMethodName) { + if (isInEditMode()) { + return; + } var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); }; diff --git a/scripts/system/edit.js b/scripts/system/edit.js index afcfd50bb8..ad04c8b139 100644 --- a/scripts/system/edit.js +++ b/scripts/system/edit.js @@ -429,7 +429,6 @@ var toolBar = (function () { }); }); - that.setActive(false); } @@ -446,6 +445,7 @@ var toolBar = (function () { }; that.setActive = function (active) { + Settings.setValue(EDIT_SETTING, active); if (active === isActive) { return; } @@ -457,7 +457,6 @@ var toolBar = (function () { enabled: active })); isActive = active; - Settings.setValue(EDIT_SETTING, active); if (!isActive) { entityListTool.setVisible(false); gridTool.setVisible(false); diff --git a/scripts/system/libraries/utils.js b/scripts/system/libraries/utils.js index 9bd29d663a..2e490e5c30 100644 --- a/scripts/system/libraries/utils.js +++ b/scripts/system/libraries/utils.js @@ -6,6 +6,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +// note: this constant is currently duplicated in edit.js +EDIT_SETTING = "io.highfidelity.isEditting"; +isInEditMode = function isInEditMode() { + return Settings.getValue(EDIT_SETTING) === "false" ? false : !!Settings.getValue(EDIT_SETTING); +}; + if (!Function.prototype.bind) { Function.prototype.bind = function(oThis) { if (typeof this !== 'function') { From d20ac20ff2cf2256dd860e16c068c01f0f0f2ace Mon Sep 17 00:00:00 2001 From: humbletim Date: Mon, 23 Jan 2017 01:31:11 -0500 Subject: [PATCH 2/6] move isInEditMode guard to setState --- scripts/system/controllers/handControllerGrab.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 51dd40fe4d..6608b9cc92 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -842,14 +842,14 @@ function MyController(hand) { }; this.callEntityMethodOnGrabbed = function(entityMethodName) { - if (isInEditMode()) { - return; - } var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(this.grabbedEntity, entityMethodName, args); }; this.setState = function(newState, reason) { + if (isInEditMode() && newState !== STATE_OFF && newState !== STATE_SEARCHING) { + return; + } setGrabCommunications((newState === STATE_DISTANCE_HOLDING) || (newState === STATE_NEAR_GRABBING)); if (WANT_DEBUG || WANT_DEBUG_STATE) { var oldStateName = stateToName(this.state); From 99e0c8c0e744e76571994728ace9f16556b7d342 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 23 Jan 2017 11:37:54 -0800 Subject: [PATCH 3/6] use fromUserInput in web entity URL set to avoid crashable URLs --- .../entities-renderer/src/RenderableWebEntityItem.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 4fdb6c84dd..2d8f52c67c 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -247,8 +247,15 @@ void RenderableWebEntityItem::render(RenderArgs* args) { void RenderableWebEntityItem::setSourceUrl(const QString& value) { if (_sourceUrl != value) { - qCDebug(entities) << "Setting web entity source URL to " << value; - _sourceUrl = value; + auto newURL = QUrl::fromUserInput(value); + + if (newURL.isValid()) { + qCDebug(entities) << "Setting web entity source URL to " << value; + _sourceUrl = newURL.toDisplayString(); + } else { + qCDebug(entities) << "Clearing web entity source URL since" << value << "cannot be parsed to a valid URL."; + } + if (_webSurface) { AbstractViewStateInterface::instance()->postLambdaEvent([this] { _webSurface->getRootItem()->setProperty("url", _sourceUrl); From d7651e98381ca7b3a2288cc3629745d7e2e4c905 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 23 Jan 2017 11:45:21 -0800 Subject: [PATCH 4/6] move value sanitizing to WebEntityItem --- .../src/RenderableWebEntityItem.cpp | 21 +++++++------------ libraries/entities/src/WebEntityItem.cpp | 9 +++++++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 2d8f52c67c..7f68738bd5 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -246,21 +246,14 @@ void RenderableWebEntityItem::render(RenderArgs* args) { } void RenderableWebEntityItem::setSourceUrl(const QString& value) { - if (_sourceUrl != value) { - auto newURL = QUrl::fromUserInput(value); + auto valueBeforeSuperclassSet = _sourceUrl; - if (newURL.isValid()) { - qCDebug(entities) << "Setting web entity source URL to " << value; - _sourceUrl = newURL.toDisplayString(); - } else { - qCDebug(entities) << "Clearing web entity source URL since" << value << "cannot be parsed to a valid URL."; - } - - if (_webSurface) { - AbstractViewStateInterface::instance()->postLambdaEvent([this] { - _webSurface->getRootItem()->setProperty("url", _sourceUrl); - }); - } + WebEntityItem::setSourceUrl(value); + + if (_sourceUrl != valueBeforeSuperclassSet && _webSurface) { + AbstractViewStateInterface::instance()->postLambdaEvent([this] { + _webSurface->getRootItem()->setProperty("url", _sourceUrl); + }); } } diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index 735ec1812a..e8a69a390d 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -125,7 +125,14 @@ bool WebEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const g void WebEntityItem::setSourceUrl(const QString& value) { if (_sourceUrl != value) { - _sourceUrl = value; + auto newURL = QUrl::fromUserInput(value); + + if (newURL.isValid()) { + qCDebug(entities) << "Setting web entity source URL to " << value; + _sourceUrl = newURL.toDisplayString(); + } else { + qCDebug(entities) << "Clearing web entity source URL since" << value << "cannot be parsed to a valid URL."; + } } } From 3f8b2f9cbb8726f3e269ed6af2abdbfdcb3d2ef7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 23 Jan 2017 11:49:07 -0800 Subject: [PATCH 5/6] Fix invalid volume values in injector options --- libraries/audio/src/AudioInjectorOptions.cpp | 78 +++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/libraries/audio/src/AudioInjectorOptions.cpp b/libraries/audio/src/AudioInjectorOptions.cpp index eca1a4197d..1a92697828 100644 --- a/libraries/audio/src/AudioInjectorOptions.cpp +++ b/libraries/audio/src/AudioInjectorOptions.cpp @@ -9,9 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include "AudioInjectorOptions.h" + +#include + #include -#include "AudioInjectorOptions.h" +#include "AudioLogging.h" AudioInjectorOptions::AudioInjectorOptions() : position(0.0f, 0.0f, 0.0f), @@ -22,7 +26,7 @@ AudioInjectorOptions::AudioInjectorOptions() : ambisonic(false), ignorePenumbra(false), localOnly(false), - secondOffset(0.0) + secondOffset(0.0f) { } @@ -40,31 +44,51 @@ QScriptValue injectorOptionsToScriptValue(QScriptEngine* engine, const AudioInje } void injectorOptionsFromScriptValue(const QScriptValue& object, AudioInjectorOptions& injectorOptions) { - if (object.property("position").isValid()) { - vec3FromScriptValue(object.property("position"), injectorOptions.position); + if (!object.isObject()) { + qWarning() << "Audio injector options is not an object."; + return; } - - if (object.property("volume").isValid()) { - injectorOptions.volume = object.property("volume").toNumber(); - } - - if (object.property("loop").isValid()) { - injectorOptions.loop = object.property("loop").toBool(); - } - - if (object.property("orientation").isValid()) { - quatFromScriptValue(object.property("orientation"), injectorOptions.orientation); - } - - if (object.property("ignorePenumbra").isValid()) { - injectorOptions.ignorePenumbra = object.property("ignorePenumbra").toBool(); - } - - if (object.property("localOnly").isValid()) { - injectorOptions.localOnly = object.property("localOnly").toBool(); - } - - if (object.property("secondOffset").isValid()) { - injectorOptions.secondOffset = object.property("secondOffset").toNumber(); + + QScriptValueIterator it(object); + while (it.hasNext()) { + it.next(); + + if (it.name() == "position") { + vec3FromScriptValue(object.property("position"), injectorOptions.position); + } else if (it.name() == "orientation") { + quatFromScriptValue(object.property("orientation"), injectorOptions.orientation); + } else if (it.name() == "volume") { + if (it.value().isNumber()) { + injectorOptions.volume = it.value().toNumber(); + } else { + qCWarning(audio) << "Audio injector options: volume is not a number"; + } + } else if (it.name() == "loop") { + if (it.value().isBool()) { + injectorOptions.loop = it.value().toBool(); + } else { + qCWarning(audio) << "Audio injector options: loop is not a boolean"; + } + } else if (it.name() == "ignorePenumbra") { + if (it.value().isBool()) { + injectorOptions.ignorePenumbra = it.value().toBool(); + } else { + qCWarning(audio) << "Audio injector options: ignorePenumbra is not a boolean"; + } + } else if (it.name() == "localOnly") { + if (it.value().isBool()) { + injectorOptions.localOnly = it.value().toBool(); + } else { + qCWarning(audio) << "Audio injector options: localOnly is not a boolean"; + } + } else if (it.name() == "secondOffset") { + if (it.value().isNumber()) { + injectorOptions.secondOffset = it.value().toNumber(); + } else { + qCWarning(audio) << "Audio injector options: secondOffset is not a number"; + } + } else { + qCWarning(audio) << "Unknown audio injector option:" << it.name(); + } } } \ No newline at end of file From f02832ca71ba4b8a5a88fbdc8412f9a1bf253b8f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 23 Jan 2017 11:50:05 -0800 Subject: [PATCH 6/6] output the actual value set in WebEntityItem --- libraries/entities/src/WebEntityItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index e8a69a390d..38ececefa4 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -128,8 +128,8 @@ void WebEntityItem::setSourceUrl(const QString& value) { auto newURL = QUrl::fromUserInput(value); if (newURL.isValid()) { - qCDebug(entities) << "Setting web entity source URL to " << value; _sourceUrl = newURL.toDisplayString(); + qCDebug(entities) << "Changed web entity source URL to " << _sourceUrl; } else { qCDebug(entities) << "Clearing web entity source URL since" << value << "cannot be parsed to a valid URL."; }