Avoid to create a route when the source is not defined

This commit is contained in:
samcake 2015-10-19 12:56:06 -07:00
parent 9ae1da371e
commit 3d8b7f9d10
3 changed files with 16 additions and 11 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -108,7 +108,7 @@ bool PolyLineEntityItem::setStrokeWidths(const QVector<float>& strokeWidths) {
bool PolyLineEntityItem::setNormals(const QVector<glm::vec3>& normals) {
_normals = normals;
if (_points.size() < 2 || _normals.size() < 2) {
if (_points.size() < 2 || _normals.size() < 2 || _strokeWidths.size() < 2) {
return false;
}