mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user