From 3d13cbc20d06c5c178b35564fdfeae3e833e8fe0 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 2 Jun 2025 22:42:33 -0700 Subject: [PATCH 1/3] Fixed reset of data. --- lib/data_state.cpp | 15 +++++++-------- lib/data_state.hpp | 12 ++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/data_state.cpp b/lib/data_state.cpp index c678a851..7a277846 100644 --- a/lib/data_state.cpp +++ b/lib/data_state.cpp @@ -572,10 +572,7 @@ bool DataState::SetNewMeshAndSolution(DataState new_state, { ResetMeshAndSolution(new_state, vs); - internal.grid_f = std::move(new_state.internal.grid_f); - internal.mesh = std::move(new_state.internal.mesh); - internal.quad_f = std::move(new_state.internal.quad_f); - internal.mesh_quad = std::move(new_state.internal.mesh_quad); + *this = std::move(new_state); return true; } @@ -593,8 +590,9 @@ void DataState::ResetMeshAndSolution(DataState &ss, VisualizationScene* vs) { VisualizationSceneSolution *vss = dynamic_cast(vs); - ss.grid_f->GetNodalValues(ss.sol); - vss->NewMeshAndSolution(ss.mesh.get(), ss.mesh_quad.get(), &ss.sol, + // use the local vector as pointer is invalid after the move + ss.grid_f->GetNodalValues(sol); + vss->NewMeshAndSolution(ss.mesh.get(), ss.mesh_quad.get(), &sol, ss.grid_f.get()); } else @@ -610,8 +608,9 @@ void DataState::ResetMeshAndSolution(DataState &ss, VisualizationScene* vs) { VisualizationSceneSolution3d *vss = dynamic_cast(vs); - ss.grid_f->GetNodalValues(ss.sol); - vss->NewMeshAndSolution(ss.mesh.get(), ss.mesh_quad.get(), &ss.sol, + // use the local vector as pointer is invalid after the move + ss.grid_f->GetNodalValues(sol); + vss->NewMeshAndSolution(ss.mesh.get(), ss.mesh_quad.get(), &sol, ss.grid_f.get()); } else diff --git a/lib/data_state.hpp b/lib/data_state.hpp index 47fdc639..8b61b1e8 100644 --- a/lib/data_state.hpp +++ b/lib/data_state.hpp @@ -62,6 +62,12 @@ struct DataState void SetGridFunctionSolution(int component = -1); void SetQuadFunctionSolution(int component = -1); + /// Updates the given VisualizationScene pointer with the new data + /// of the given DataState object. + /// @note: Use with caution when the update is compatible + /// @see SetNewMeshAndSolution() + void ResetMeshAndSolution(DataState &ss, VisualizationScene* vs); + public: mfem::Vector sol, solu, solv, solw, normals; const std::unique_ptr &mesh{internal.mesh}; @@ -168,12 +174,6 @@ struct DataState /// updated. bool SetNewMeshAndSolution(DataState new_state, VisualizationScene* vs); - - /// Updates the given VisualizationScene pointer with the new data - /// of the given DataState object. - /// @note: Use with caution when the update is compatible - /// @see SetNewMeshAndSolution() - static void ResetMeshAndSolution(DataState &ss, VisualizationScene* vs); }; #endif // GLVIS_DATA_STATE_HPP From 83bbd12cbc58d45e276a27a01ba9f6894b88cd1d Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 2 Jun 2025 23:06:58 -0700 Subject: [PATCH 2/3] Fixed move of data. --- lib/data_state.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/data_state.cpp b/lib/data_state.cpp index 7a277846..b4225817 100644 --- a/lib/data_state.cpp +++ b/lib/data_state.cpp @@ -572,7 +572,8 @@ bool DataState::SetNewMeshAndSolution(DataState new_state, { ResetMeshAndSolution(new_state, vs); - *this = std::move(new_state); + // do not sol vector as it is updated directly + internal = std::move(new_state.internal); return true; } From 4072793dff56884cb30878112484fff1f199fa09 Mon Sep 17 00:00:00 2001 From: Jan Nikl Date: Mon, 2 Jun 2025 23:21:19 -0700 Subject: [PATCH 3/3] Fixed typo. --- lib/data_state.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data_state.cpp b/lib/data_state.cpp index b4225817..287cb68c 100644 --- a/lib/data_state.cpp +++ b/lib/data_state.cpp @@ -572,7 +572,7 @@ bool DataState::SetNewMeshAndSolution(DataState new_state, { ResetMeshAndSolution(new_state, vs); - // do not sol vector as it is updated directly + // do not move 'sol' vector as it is updated directly internal = std::move(new_state.internal); return true;