From dcd22490395ef981bbbfbe8d67499a3735c49f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 23 Apr 2017 10:49:01 +0200 Subject: [PATCH] Platform: no need to have things at such level of ugliness. --- src/Magnum/Platform/Sdl2Application.cpp | 18 +++--------------- src/Magnum/Platform/Sdl2Application.h | 5 ----- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index ce00993be..a20544349 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -58,13 +58,6 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) { } -#ifdef CORRADE_TARGET_EMSCRIPTEN -Sdl2Application* Sdl2Application::_instance = nullptr; -void Sdl2Application::staticMainLoop() { - _instance->mainLoop(); -} -#endif - #ifndef DOXYGEN_GENERATING_OUTPUT Sdl2Application::Sdl2Application(const Arguments& arguments): Sdl2Application{arguments, Configuration{}} {} #endif @@ -79,11 +72,6 @@ Sdl2Application::Sdl2Application(const Arguments& arguments, NoCreateT): _glCont #endif _context{new Context{NoCreate, arguments.argc, arguments.argv}}, _flags{Flag::Redraw} { - #ifdef CORRADE_TARGET_EMSCRIPTEN - CORRADE_ASSERT(!_instance, "Platform::Sdl2Application::Sdl2Application(): the instance is already created", ); - _instance = this; - #endif - if(SDL_Init(SDL_INIT_VIDEO) < 0) { Error() << "Cannot initialize SDL."; std::exit(1); @@ -325,8 +313,6 @@ Sdl2Application::~Sdl2Application() { SDL_DestroyWindow(_window); #else SDL_FreeSurface(_glContext); - CORRADE_INTERNAL_ASSERT(_instance == this); - _instance = nullptr; #endif SDL_Quit(); } @@ -335,7 +321,9 @@ int Sdl2Application::exec() { #ifndef CORRADE_TARGET_EMSCRIPTEN while(!(_flags & Flag::Exit)) mainLoop(); #else - emscripten_set_main_loop(staticMainLoop, 0, true); + emscripten_set_main_loop_arg([](void* arg) { + static_cast(arg)->mainLoop(); + }, this, 0, true); #endif return 0; } diff --git a/src/Magnum/Platform/Sdl2Application.h b/src/Magnum/Platform/Sdl2Application.h index c859a9cf9..6b14dc623 100644 --- a/src/Magnum/Platform/Sdl2Application.h +++ b/src/Magnum/Platform/Sdl2Application.h @@ -710,11 +710,6 @@ class Sdl2Application { typedef Containers::EnumSet Flags; CORRADE_ENUMSET_FRIEND_OPERATORS(Flags) - #ifdef CORRADE_TARGET_EMSCRIPTEN - static Sdl2Application* _instance; - static void staticMainLoop(); - #endif - void mainLoop(); #ifndef CORRADE_TARGET_EMSCRIPTEN