[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.
This commit is contained in:
Peter Johnson
2021-03-21 18:06:18 -07:00
committed by GitHub
parent 2d2eaa3eff
commit 10c038d9bf

View File

@@ -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<int>(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<int>(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<PlotView>(this))) {
win->SetDefaultSize(700, 400);
}