From 10c038d9bfabea683c67465301934ed281f3bd1c Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 21 Mar 2021 18:06:18 -0700 Subject: [PATCH] [glass] Plot: Fix window creation after removal (#3264) Previously the following sequence was broken: - Add two plot windows (creates Plot<0> and Plot<1>) - Delete Plot<0> - Try to create a plot window This failed because it would try to create Plot<1>, which already existed. It was necessary to also destroy Plot<1> before another plot could be added. This change fixes this case by trying all 0-N cases. --- glass/src/lib/native/cpp/other/Plot.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/glass/src/lib/native/cpp/other/Plot.cpp b/glass/src/lib/native/cpp/other/Plot.cpp index 4a9514aa63..ebb132aef2 100644 --- a/glass/src/lib/native/cpp/other/Plot.cpp +++ b/glass/src/lib/native/cpp/other/Plot.cpp @@ -989,9 +989,22 @@ void PlotProvider::DisplayMenu() { } if (ImGui::MenuItem("New Plot Window")) { + // this is an inefficient algorithm, but the number of windows is small char id[32]; - std::snprintf(id, sizeof(id), "Plot <%d>", - static_cast(m_windows.size())); + size_t numWindows = m_windows.size(); + for (size_t i = 0; i <= numWindows; ++i) { + std::snprintf(id, sizeof(id), "Plot <%d>", static_cast(i)); + bool match = false; + for (size_t j = i; j < numWindows; ++j) { + if (m_windows[j]->GetId() == id) { + match = true; + break; + } + } + if (!match) { + break; + } + } if (auto win = AddWindow(id, std::make_unique(this))) { win->SetDefaultSize(700, 400); }