From aeea8a49128f0efb5ef4de28e5ff562c138e24b1 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Fri, 29 Apr 2022 04:42:18 -0500 Subject: [PATCH] GUI: prevent division by zero --- src/gui/newSong.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gui/newSong.cpp b/src/gui/newSong.cpp index 06aeb4bd6..2bf11fb5c 100644 --- a/src/gui/newSong.cpp +++ b/src/gui/newSong.cpp @@ -66,16 +66,24 @@ void FurnaceGUI::drawNewSong() { ImGui::EndTable(); } - if (ImGui::Button("Cancel")) { - ImGui::CloseCurrentPopup(); + if (ImGui::Button("I'm feeling lucky")) { + if (sysCategories.size()==0) { + ImGui::CloseCurrentPopup(); + } else { + FurnaceGUISysCategory* newSystemCat=&sysCategories[rand()%sysCategories.size()]; + if (newSystemCat->systems.size()==0) { + ImGui::CloseCurrentPopup(); + } else { + nextDesc=newSystemCat->systems[rand()%newSystemCat->systems.size()].definition.data(); + accepted=true; + } + } } ImGui::SameLine(); - if (ImGui::Button("I'm feeling lucky")) { - FurnaceGUISysCategory* newSystemCat=&sysCategories[rand()%sysCategories.size()]; - nextDesc=newSystemCat->systems[rand()%newSystemCat->systems.size()].definition.data(); - accepted=true; + if (ImGui::Button("Cancel")) { + ImGui::CloseCurrentPopup(); } if (accepted) { @@ -95,4 +103,4 @@ void FurnaceGUI::drawNewSong() { updateWindowTitle(); ImGui::CloseCurrentPopup(); } -} \ No newline at end of file +}