From 6bf59e4c2d77ed44b861f01b994607150209addd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 9 Nov 2024 20:11:31 -0500 Subject: [PATCH] [cables] Be more lenient with disappearing cables --- .../Dataflow/Commands/CableHelpers.cpp | 7 +++++-- .../Dataflow/Commands/EditConnection.cpp | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/plugins/score-plugin-scenario/Dataflow/Commands/CableHelpers.cpp b/src/plugins/score-plugin-scenario/Dataflow/Commands/CableHelpers.cpp index 31cfae2506..e4f81ae84f 100644 --- a/src/plugins/score-plugin-scenario/Dataflow/Commands/CableHelpers.cpp +++ b/src/plugins/score-plugin-scenario/Dataflow/Commands/CableHelpers.cpp @@ -136,8 +136,11 @@ void removeCables(const SerializedCables& cables, const score::DocumentContext& if(cable_it != doc.cables.end()) { auto& cable = *cable_it; - cable.source().find(ctx).removeCable(cable); - cable.sink().find(ctx).removeCable(cable); + if(auto c = cable.source().try_find(ctx)) + c->removeCable(cable); + + if(auto c = cable.sink().try_find(ctx)) + c->removeCable(cable); doc.cables.remove(cid.first); } else diff --git a/src/plugins/score-plugin-scenario/Dataflow/Commands/EditConnection.cpp b/src/plugins/score-plugin-scenario/Dataflow/Commands/EditConnection.cpp index 9aec2ad799..495e618665 100644 --- a/src/plugins/score-plugin-scenario/Dataflow/Commands/EditConnection.cpp +++ b/src/plugins/score-plugin-scenario/Dataflow/Commands/EditConnection.cpp @@ -54,13 +54,21 @@ void CreateCable::redo(const score::DocumentContext& ctx) const model.cables.add(c); auto ext = m_model.extend(m_cable); - auto& source = m_dat.source.find(ctx); - source.addCable(*c); - m_dat.sink.find(ctx).addCable(*c); + auto source = m_dat.source.try_find(ctx); + if(source) + source->addCable(*c); + else + return; + + auto sink = m_dat.sink.try_find(ctx); + if(sink) + sink->addCable(*c); + else + return; if(m_previousPropagate) { - static_cast(source).setPropagate(false); + static_cast(*source).setPropagate(false); } }