diff --git a/dependencies/subprojects/animationwindow/include/AnimationWindow.h b/dependencies/subprojects/animationwindow/include/AnimationWindow.h index c9211b7bc98a8c81e088d3a3b027e752992f38c6..b63887fbe5eed7baa212de07723fd022b4151176 100644 --- a/dependencies/subprojects/animationwindow/include/AnimationWindow.h +++ b/dependencies/subprojects/animationwindow/include/AnimationWindow.h @@ -41,10 +41,12 @@ class AnimationWindow { private: void show_frame(); void update_gui(); + void pump_events(); TDT4102::Point getWindowDimensions() const; void startNuklearDraw(TDT4102::Point location, std::string uniqueWindowName, unsigned int width = 0, unsigned int height = 0); void endNuklearDraw(); void destroy(); + bool destroyed = false; // If set to true, new shapes will be drawn on top of the old ones. Can create some neat effects. // However, note that GUI elements such as buttons will not draw themselves correctly if you use this. diff --git a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp index 15385aa28a636895426e77632393ada62d750704..14c872c50c3c5d585261eb0cee822abd4a2e6f08 100644 --- a/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp +++ b/dependencies/subprojects/animationwindow/src/AnimationWindow.cpp @@ -60,6 +60,8 @@ TDT4102::AnimationWindow::~AnimationWindow() { } void TDT4102::AnimationWindow::destroy() { + this->destroyed = true; + // Free SDL resources depending on how much ended up being initialised in the constructor if (rendererHandle != nullptr) { SDL_DestroyRenderer(rendererHandle); @@ -73,14 +75,16 @@ void TDT4102::AnimationWindow::destroy() { nk_free(context); context = nullptr; } + // Needed for MacOS + // Window does not close unless the events are pumped + // after requesting that + pump_events(); } -void TDT4102::AnimationWindow::show_frame() { - SDL_RenderPresent(rendererHandle); - deltaMouseWheel = 0; - +void TDT4102::AnimationWindow::pump_events() { SDL_Event event; - nk_input_begin(context); + SDL_PumpEvents(); + while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { closeRequested = true; @@ -107,8 +111,18 @@ void TDT4102::AnimationWindow::show_frame() { deltaMouseWheel = event.wheel.preciseY; // The amount scrolled vertically, positive away from the user and negative toward the user } - nk_sdl_handle_event(&event); + if(!destroyed) { + nk_sdl_handle_event(&event); + } + } +} + +void TDT4102::AnimationWindow::show_frame() { + SDL_RenderPresent(rendererHandle); + deltaMouseWheel = 0; + nk_input_begin(context); + pump_events(); nk_input_end(context); }