Skip to content
Snippets Groups Projects
Commit 2a4fce5e authored by Mederic Fourmy's avatar Mederic Fourmy
Browse files

Add an error when getState is called with wrong stateblock

parent 2ce80a8e
No related branches found
No related tags found
1 merge request!450Resolve "HasStateBlocks::getState behaves in a non predictible way"
Pipeline #11503 failed
...@@ -349,8 +349,9 @@ inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) ...@@ -349,8 +349,9 @@ inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure)
for (const char key : structure) for (const char key : structure)
{ {
const auto& sb = getStateBlock(key); const auto& sb = getStateBlock(key);
if (sb == nullptr){
assert(sb != nullptr && "Requested StateBlock key not in the structure"); throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.segment(index,sb->getSize()) = sb->getState(); state.segment(index,sb->getSize()) = sb->getState();
index += sb->getSize(); index += sb->getSize();
...@@ -367,8 +368,9 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure ...@@ -367,8 +368,9 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure
for (const auto key : structure) for (const auto key : structure)
{ {
const auto& sb = getStateBlock(key); const auto& sb = getStateBlock(key);
if (sb == nullptr){
assert(sb != nullptr && "Requested StateBlock key not in the structure"); throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.emplace(key, sb->getState()); state.emplace(key, sb->getState());
} }
......
...@@ -209,15 +209,6 @@ TEST_F(HasStateBlocksTest, getState_structure) ...@@ -209,15 +209,6 @@ TEST_F(HasStateBlocksTest, getState_structure)
ASSERT_TRUE(state0.count('P')); ASSERT_TRUE(state0.count('P'));
ASSERT_FALSE(state0.count('O')); ASSERT_FALSE(state0.count('O'));
ASSERT_TRUE(state0.count('V')); ASSERT_TRUE(state0.count('V'));
state0 = F0->getState("OW"); // W does not exist
WOLF_DEBUG("getState(\"OW\") = ", state0);
ASSERT_EQ(state0.size(), 1);
ASSERT_FALSE(state0.count('P'));
ASSERT_TRUE(state0.count('O'));
ASSERT_FALSE(state0.count('V'));
ASSERT_FALSE(state0.count('W'));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment