From 77feda0c0fad941b81dcdaed090a3ede713f97cd Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Wed, 28 Aug 2024 21:10:43 +0200 Subject: [PATCH] b simulators got std::out_of_range on substr exception with 10 as size and this is the only place i use substr with size 10 --- tools/simulators.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/simulators.cpp b/tools/simulators.cpp index c4085ac..1f78a4b 100644 --- a/tools/simulators.cpp +++ b/tools/simulators.cpp @@ -119,15 +119,22 @@ json Simulators::changed_UI_items() // Then push the ui_item at that index to the changed json std::unordered_set addedIndices; - for (auto& item : diff) + try { - std::string path = item["path"]; - size_t index = std::stoul(path.substr(10, path.find("/", 10) - 10)); - if (addedIndices.find(index) != addedIndices.end()) - continue; - - changed["event"]["UI_items"].push_back(after["UI_items"][index]); - addedIndices.insert(index); + for (auto& item : diff) + { + std::string path = item["path"]; + size_t index = std::stoul(path.substr(10, path.find("/", 10) - 10)); + if (addedIndices.find(index) != addedIndices.end()) + continue; + + changed["event"]["UI_items"].push_back(after["UI_items"][index]); + addedIndices.insert(index); + } + } + catch(const std::exception& e) + { + spdlog::error(e.what()); } m_before = after;