From 3d8b7f9d108721605821fbc853108261f88ecb70 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 19 Oct 2015 12:56:06 -0700 Subject: [PATCH] Avoid to create a route when the source is not defined --- .../src/controllers/ScriptingInterface.cpp | 2 +- .../controllers/impl/MappingBuilderProxy.cpp | 23 +++++++++++-------- libraries/entities/src/PolyLineEntityItem.cpp | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index c5c7969604..3e470fd365 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -300,7 +300,7 @@ namespace controller { const auto& destination = route->_destination; // THis could happen if the route destination failed to create // FIXME: Maybe do not create the route if the destination failed and avoid this case ? - if (!destination) { + if (!source || !destination) { continue; } diff --git a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp index e75068b311..bde10defdc 100644 --- a/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp +++ b/libraries/controllers/src/controllers/impl/MappingBuilderProxy.cpp @@ -39,9 +39,14 @@ QObject* MappingBuilderProxy::from(const QScriptValue& source) { } QObject* MappingBuilderProxy::from(const Endpoint::Pointer& source) { - auto route = Route::Pointer(new Route()); - route->_source = source; - return new RouteBuilderProxy(_parent, _mapping, route); + if (source) { + auto route = Route::Pointer(new Route()); + route->_source = source; + return new RouteBuilderProxy(_parent, _mapping, route); + } else { + qCDebug(controllers) << "MappingBuilderProxy::from : source is null so no route created"; + return nullptr; + } } QObject* MappingBuilderProxy::makeAxis(const QJSValue& source1, const QJSValue& source2) { @@ -60,16 +65,16 @@ const QString JSON_CHANNEL_FILTERS = QStringLiteral("filters"); void MappingBuilderProxy::parse(const QJsonObject& json) { _mapping->_name = json[JSON_NAME].toString(); - _mapping->_channelMappings.clear(); - const auto& jsonChannels = json[JSON_CHANNELS].toArray(); - for (const auto& channelIt : jsonChannels) { + _mapping->_channelMappings.clear(); + const auto& jsonChannels = json[JSON_CHANNELS].toArray(); + for (const auto& channelIt : jsonChannels) { parseRoute(channelIt); } } void MappingBuilderProxy::parseRoute(const QJsonValue& json) { if (json.isObject()) { - const auto& jsonChannel = json.toObject(); + const auto& jsonChannel = json.toObject(); auto newRoute = from(jsonChannel[JSON_CHANNEL_FROM]); if (newRoute) { @@ -81,8 +86,8 @@ void MappingBuilderProxy::parseRoute(const QJsonValue& json) { } QObject* MappingBuilderProxy::from(const QJsonValue& json) { - if (json.isString()) { - return from(_parent.endpointFor(_parent.inputFor(json.toString()))); + if (json.isString()) { + return from(_parent.endpointFor(_parent.inputFor(json.toString()))); } else if (json.isObject()) { // Endpoint is defined as an object, we expect a js function then return nullptr; diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 352d0425bf..e2b55302d1 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -108,7 +108,7 @@ bool PolyLineEntityItem::setStrokeWidths(const QVector& strokeWidths) { bool PolyLineEntityItem::setNormals(const QVector& normals) { _normals = normals; - if (_points.size() < 2 || _normals.size() < 2) { + if (_points.size() < 2 || _normals.size() < 2 || _strokeWidths.size() < 2) { return false; }