From 0c45409dfefe016785bb8e3a09ce4ca68df9f877 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 19 Feb 2021 10:43:07 +0300 Subject: [PATCH] App bugfix: event handler can change while handling events --- libs/app/source/app.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index e064e4a5..18af5768 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -125,7 +125,7 @@ namespace psemek::app void app::poll_events() { - auto handler = impl().get_scene(); + auto handler = [this]{ return impl().get_scene(); }; for (SDL_Event e; SDL_PollEvent(&e);) switch (e.type) { @@ -136,33 +136,33 @@ namespace psemek::app { case SDL_WINDOWEVENT_RESIZED: impl().had_initial_resize = true; - handler->on_resize(e.window.data1, e.window.data2); + handler()->on_resize(e.window.data1, e.window.data2); break; case SDL_WINDOWEVENT_FOCUS_GAINED: - handler->on_focus_gained(); + handler()->on_focus_gained(); break; case SDL_WINDOWEVENT_FOCUS_LOST: - handler->on_focus_lost(); + handler()->on_focus_lost(); break; } break; case SDL_MOUSEMOTION: - handler->on_mouse_move(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel); + handler()->on_mouse_move(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel); break; case SDL_MOUSEWHEEL: - handler->on_mouse_wheel(e.wheel.y); + handler()->on_mouse_wheel(e.wheel.y); break; case SDL_MOUSEBUTTONDOWN: switch (e.button.button) { case SDL_BUTTON_LEFT: - handler->on_left_button_down(); + handler()->on_left_button_down(); break; case SDL_BUTTON_MIDDLE: - handler->on_middle_button_down(); + handler()->on_middle_button_down(); break; case SDL_BUTTON_RIGHT: - handler->on_right_button_down(); + handler()->on_right_button_down(); break; } break; @@ -170,21 +170,21 @@ namespace psemek::app switch (e.button.button) { case SDL_BUTTON_LEFT: - handler->on_left_button_up(); + handler()->on_left_button_up(); break; case SDL_BUTTON_MIDDLE: - handler->on_middle_button_up(); + handler()->on_middle_button_up(); break; case SDL_BUTTON_RIGHT: - handler->on_right_button_up(); + handler()->on_right_button_up(); break; } break; case SDL_KEYDOWN: - handler->on_key_down(e.key.keysym.sym); + handler()->on_key_down(e.key.keysym.sym); break; case SDL_KEYUP: - handler->on_key_up(e.key.keysym.sym); + handler()->on_key_up(e.key.keysym.sym); break; } }