@@ -166,17 +166,22 @@ void CableWidget::setCable(engine::Cable* cable) { | |||||
delete this->cable; | delete this->cable; | ||||
this->cable = NULL; | this->cable = NULL; | ||||
} | } | ||||
this->cable = cable; | |||||
if (cable) { | if (cable) { | ||||
app::ModuleWidget* outputModule = APP->scene->rack->getModule(cable->outputModule->id); | |||||
assert(outputModule); | |||||
outputPort = outputModule->getOutput(cable->outputId); | |||||
assert(outputPort); | |||||
app::ModuleWidget* inputModule = APP->scene->rack->getModule(cable->inputModule->id); | |||||
assert(inputModule); | |||||
inputPort = inputModule->getInput(cable->inputId); | |||||
assert(inputPort); | |||||
app::ModuleWidget* outputMw = APP->scene->rack->getModule(cable->outputModule->id); | |||||
if (!outputMw) | |||||
throw Exception("Cable cannot find output ModuleWidget %lld", cable->outputModule->id); | |||||
outputPort = outputMw->getOutput(cable->outputId); | |||||
if (!outputPort) | |||||
throw Exception("Cable cannot find output port %d", cable->outputId); | |||||
app::ModuleWidget* inputMw = APP->scene->rack->getModule(cable->inputModule->id); | |||||
if (!inputMw) | |||||
throw Exception("Cable cannot find input ModuleWidget %lld", cable->inputModule->id); | |||||
inputPort = inputMw->getInput(cable->inputId); | |||||
if (!inputPort) | |||||
throw Exception("Cable cannot find input port %d", cable->inputId); | |||||
this->cable = cable; | |||||
} | } | ||||
else { | else { | ||||
outputPort = NULL; | outputPort = NULL; | ||||
@@ -395,6 +395,7 @@ void RackWidget::fromJson(json_t* rootJ) { | |||||
// Get cable ID | // Get cable ID | ||||
json_t* idJ = json_object_get(cableJ, "id"); | json_t* idJ = json_object_get(cableJ, "id"); | ||||
int64_t id; | int64_t id; | ||||
// In <=v0.6, the cable ID was the index in the array. | |||||
if (idJ) | if (idJ) | ||||
id = json_integer_value(idJ); | id = json_integer_value(idJ); | ||||
else | else | ||||
@@ -409,11 +410,20 @@ void RackWidget::fromJson(json_t* rootJ) { | |||||
// Create CableWidget | // Create CableWidget | ||||
CableWidget* cw = new CableWidget; | CableWidget* cw = new CableWidget; | ||||
cw->setCable(cable); | |||||
cw->fromJson(cableJ); | |||||
// In <=v1, cable colors were not serialized, so choose one from the available colors. | |||||
if (cw->color.a == 0.f) { | |||||
cw->color = getNextCableColor(); | |||||
try { | |||||
cw->setCable(cable); | |||||
cw->fromJson(cableJ); | |||||
// In <=v1, cable colors were not serialized, so choose one from the available colors. | |||||
if (cw->color.a == 0.f) { | |||||
cw->color = getNextCableColor(); | |||||
} | |||||
} | |||||
catch (Exception& e) { | |||||
delete cw; | |||||
// If creating CableWidget fails, remove Cable from Engine. | |||||
APP->engine->removeCable(cable); | |||||
delete cable; | |||||
continue; | |||||
} | } | ||||
addCable(cw); | addCable(cw); | ||||
} | } | ||||