From 461b92ccc3496321122fdfecc34518ec846922c3 Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Mon, 6 May 2024 17:02:50 +0500 Subject: [PATCH] gui error handler --- src/UsefulException.cpp | 2 +- src/gui/gui.cpp | 87 +++++++++++++++++++++++++++++++++++++---- src/gui/gui.hpp | 3 +- src/main.cpp | 13 +++--- 4 files changed, 90 insertions(+), 15 deletions(-) diff --git a/src/UsefulException.cpp b/src/UsefulException.cpp index 48e6b02..5e9e8ac 100644 --- a/src/UsefulException.cpp +++ b/src/UsefulException.cpp @@ -6,7 +6,7 @@ UsefulException_::UsefulException_(const std::string& _message, const std::strin { std::stringstream ss; ss<draw(); + } + } + catch(const std::exception& e){ + error_message = "Catched exception: " + std::string(e.what()); + draw_error_window = true; + std::cerr<draw(); + draw_ui(); // Rendering ImGui::Render(); + ImGuiIO& io = ImGui::GetIO(); glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); glClear(GL_COLOR_BUFFER_BIT); @@ -230,12 +272,43 @@ void GUI::draw_bg_window(){ ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), dockspace_flags); // MenuBar - //TODO + if(ImGui::BeginMainMenuBar()){ + if(ImGui::BeginMenu("test")){ + if(ImGui::MenuItem("throw exception")){ + ImGui::EndMenu(); + ImGui::EndMainMenuBar(); + ImGui::End(); + throw UsefulException("example exception"); + } + if(ImGui::MenuItem("throw const char*")){ + ImGui::EndMenu(); + ImGui::EndMainMenuBar(); + ImGui::End(); + throw "cptr"; + } + if(ImGui::MenuItem("throw std::string")){ + ImGui::EndMenu(); + ImGui::EndMainMenuBar(); + ImGui::End(); + throw std::string("str"); + } + if(ImGui::MenuItem("throw unknown")){ + ImGui::EndMenu(); + ImGui::EndMainMenuBar(); + ImGui::End(); + throw 111; + } + ImGui::EndMenu(); + } + ImGui::EndMainMenuBar(); + } ImGui::End(); } -void GUI::draw_debug_window(ImGuiIO& io){ +void GUI::draw_debug_window(){ + ImGuiIO& io = ImGui::GetIO(); + ImGui::Begin("Debug Options"); ImGui::ColorEdit3("clear_color", (float*)&clear_color); ImGui::Checkbox("main_loop_wait_for_input", &main_loop_wait_for_input); diff --git a/src/gui/gui.hpp b/src/gui/gui.hpp index b317828..3530cc1 100644 --- a/src/gui/gui.hpp +++ b/src/gui/gui.hpp @@ -48,7 +48,8 @@ private: void destroy(); void poll_events(u16& frame_updates_requested, bool wait); void draw_frame(); - void draw_debug_window(ImGuiIO &io); + void draw_ui(); + void draw_debug_window(); void draw_bg_window(); }; diff --git a/src/main.cpp b/src/main.cpp index 8274c38..dc1d200 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ -#include "gui/gui.hpp" #include +#include "gui/gui.hpp" + // SDL for some reason redefines main #ifdef main @@ -23,16 +24,16 @@ int main(const int argc, const char* const* argv){ std::cerr<<"Catched exception: "<