From 636e552e16890664ea07f5fd9bd2199cbaf86e8c Mon Sep 17 00:00:00 2001
From: Mederic Fourmy <mederic.fourmy@gmail.com>
Date: Fri, 20 May 2022 17:31:52 +0200
Subject: [PATCH] [skip-ci] fix the ::getState() bug but gtest_has_state_blocks
 fails

---
 include/core/state_block/has_state_blocks.h | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/core/state_block/has_state_blocks.h b/include/core/state_block/has_state_blocks.h
index ac82297f5..95e2f83f5 100644
--- a/include/core/state_block/has_state_blocks.h
+++ b/include/core/state_block/has_state_blocks.h
@@ -341,11 +341,7 @@ inline void HasStateBlocks::setState(const StateStructure& _structure, const std
 //// _structure can be either stateblock structure of the node or a subset of this structure
 inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) const
 {
-    StateStructure structure;
-    if (_structure == "")
-        structure = structure_;
-    else
-        structure = _structure;
+    const StateStructure& structure = (_structure == "" ? structure_ : _structure);
 
     VectorXd state(getSize(structure));
 
@@ -370,11 +366,11 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure
 
     for (const auto key : structure)
     {
-        auto state_it = state_block_map_.find(key);
+        const auto& sb = getStateBlock(key);
 
-        if (state_it != state_block_map_.end())
+        assert(sb != nullptr && "Requested StateBlock key not in the structure");
 
-            state.emplace(key, state_it->second->getState());
+        state.emplace(key, sb->getState());
     }
 
     return state;
-- 
GitLab