From 18f5c9d025046aecf26fca84def127c1f7890bd6 Mon Sep 17 00:00:00 2001 From: Tim Nebel Date: Sat, 22 Jul 2023 01:18:08 +0200 Subject: [PATCH] made rails delete themselves if they don't have any waypoints to avoid crashes when trying to add rail points to an empty rail --- src/PropertiesWidget.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/PropertiesWidget.cpp b/src/PropertiesWidget.cpp index 6eb94da..872236d 100644 --- a/src/PropertiesWidget.cpp +++ b/src/PropertiesWidget.cpp @@ -159,10 +159,23 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){ i++; } - if(ImGui::Button((ICON_FA_PLUS "##" + Id).c_str())) { - RailPoint rp = RailPoint(rail->Points.back()); - rp.runtimeID = rand(); - rail->Points.push_back(rp); + + if(rail->Points.size() != 1) { + if (ImGui::Button((ICON_FA_PLUS "##" + Id).c_str())) { + RailPoint rp = RailPoint(rail->Points.back()); + rp.runtimeID = rand(); + rail->Points.push_back(rp); + } + } + + if(rail->Points.empty()){ + auto& map = GetMainWindow()->loadedMap; + + std::erase_if(map.Rails,[&](const Rail& rail1){ + return rail1.runtimeID == rail->runtimeID; + }); + + GetMainWindow()->selectedElem = nullptr; } ImGui::Unindent(); }