From 399e1cba3e82af784d67519baa3a54f3893a8c09 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 6 Mar 2023 17:32:22 -0500 Subject: [PATCH] Prevent infinite recursion in Solution callbacks --- src/base/Solution.cpp | 6 ++++++ src/oneD/IonFlow.cpp | 4 ++-- src/oneD/StFlow.cpp | 14 ++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/base/Solution.cpp b/src/base/Solution.cpp index bc00250ad0..65d89d3cf5 100644 --- a/src/base/Solution.cpp +++ b/src/base/Solution.cpp @@ -48,6 +48,9 @@ void Solution::setThermo(shared_ptr thermo) { } void Solution::setKinetics(shared_ptr kinetics) { + if (kinetics == m_kinetics) { + return; + } m_kinetics = kinetics; if (m_kinetics) { m_kinetics->setRoot(shared_from_this()); @@ -58,6 +61,9 @@ void Solution::setKinetics(shared_ptr kinetics) { } void Solution::setTransport(shared_ptr transport) { + if (transport == m_transport) { + return; + } m_transport = transport; for (const auto& [id, callback] : m_changeCallbacks) { callback(); diff --git a/src/oneD/IonFlow.cpp b/src/oneD/IonFlow.cpp index 6fdd885e10..09f758416d 100644 --- a/src/oneD/IonFlow.cpp +++ b/src/oneD/IonFlow.cpp @@ -74,8 +74,8 @@ IonFlow::IonFlow(shared_ptr sol, const std::string& id, size_t points) setTransportModel("Ion"); } m_solution->registerChangedCallback(this, [this]() { - setKinetics(*m_solution->kinetics()); - setTransport(*m_solution->transport()); + setKinetics(m_solution->kinetics()); + setTransport(m_solution->transport()); }); } diff --git a/src/oneD/StFlow.cpp b/src/oneD/StFlow.cpp index 3f2b77bdbb..dca412c20a 100644 --- a/src/oneD/StFlow.cpp +++ b/src/oneD/StFlow.cpp @@ -131,8 +131,8 @@ StFlow::StFlow(shared_ptr sol, const std::string& id, size_t points) setTransportModel("Mix"); } m_solution->registerChangedCallback(this, [this]() { - setKinetics(*m_solution->kinetics()); - setTransport(*m_solution->transport()); + setKinetics(m_solution->kinetics()); + setTransport(m_solution->transport()); }); } @@ -161,9 +161,8 @@ void StFlow::setKinetics(shared_ptr kin) void StFlow::setKinetics(Kinetics& kin) { - // @todo: resolve crash for updated m_solution->registerChangedCallback - // warn_deprecated("StFlow::setKinetics", - // "To be removed after Cantera 3.0. Replaced by Domain1D::setKinetics."); + warn_deprecated("StFlow::setKinetics(Kinetics&)", "To be removed after Cantera 3.0." + " Replaced by setKinetics(shared_ptr)."); m_kin = &kin; } @@ -258,9 +257,8 @@ std::string StFlow::transportModel() const { void StFlow::setTransport(Transport& trans) { - // @todo: resolve crash for updated m_solution->registerChangedCallback - // warn_deprecated("StFlow::setTransport", - // "To be removed after Cantera 3.0. Replaced by Domain1D::setTransport."); + warn_deprecated("StFlow::setTransport(Transport&)", "To be removed after" + " Cantera 3.0. Replaced by setTransport(shared_ptr)."); m_trans = &trans; if (m_trans->transportModel() == "None") { throw CanteraError("StFlow::setTransport",