made rails delete themselves if they don't have any waypoints to avoid crashes when trying to add rail points to an empty rail

This commit is contained in:
Tim Nebel 2023-07-22 01:18:08 +02:00
commit 18f5c9d025

View file

@ -159,10 +159,23 @@ void ImGuiDrawElem(Element* elem,std::string Id = ""){
i++; i++;
} }
if(ImGui::Button((ICON_FA_PLUS "##" + Id).c_str())) {
RailPoint rp = RailPoint(rail->Points.back()); if(rail->Points.size() != 1) {
rp.runtimeID = rand(); if (ImGui::Button((ICON_FA_PLUS "##" + Id).c_str())) {
rail->Points.push_back(rp); 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(); ImGui::Unindent();
} }