diff --git a/include/cantera/base/SolutionArray.h b/include/cantera/base/SolutionArray.h index 61336a7e4..0058c797e 100644 --- a/include/cantera/base/SolutionArray.h +++ b/include/cantera/base/SolutionArray.h @@ -39,7 +39,7 @@ private: SolutionArray(const SolutionArray& arr, const vector& indices); public: - virtual ~SolutionArray() {} + virtual ~SolutionArray(); /** * Instantiate a new SolutionArray reference. diff --git a/src/base/SolutionArray.cpp b/src/base/SolutionArray.cpp index 162a88173..000c2328d 100644 --- a/src/base/SolutionArray.cpp +++ b/src/base/SolutionArray.cpp @@ -44,11 +44,12 @@ SolutionArray::SolutionArray(const shared_ptr& sol, , m_dataSize(size) , m_meta(meta) { - if (!m_sol) { + if (!m_sol || !m_sol->thermo()) { throw CanteraError("SolutionArray::SolutionArray", "Unable to create SolutionArray from invalid Solution object."); } m_stride = m_sol->thermo()->stateSize(); + m_sol->thermo()->addSpeciesLock(); m_data = make_shared>(m_dataSize * m_stride, 0.); m_extra = make_shared>(); m_order = make_shared>(); @@ -72,6 +73,7 @@ SolutionArray::SolutionArray(const SolutionArray& other, , m_shared(true) , m_active(selected) { + m_sol->thermo()->addSpeciesLock(); for (auto loc : m_active) { if (loc < 0 || loc >= (int)m_dataSize) { IndexError("SolutionArray::SolutionArray", "indices", loc, m_dataSize); @@ -83,6 +85,11 @@ SolutionArray::SolutionArray(const SolutionArray& other, } } +SolutionArray::~SolutionArray() +{ + m_sol->thermo()->removeSpeciesLock(); +} + namespace { // restrict scope of helper functions to local translation unit template