@@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626
2727#include " ../../application.hpp"
2828
29+ #if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
30+ # include < emscripten.h>
31+ #endif
32+
2933#if CFG_COMPILER == CFG_COMPILER_MSVC
3034# include < SDL.h>
3135#else
@@ -632,10 +636,12 @@ void main_loop_iteration(void* user_data)
632636 // clamp to_wait_ms to max of int as SDL_WaitEventTimeout() accepts int type
633637 to_wait_ms = std::min (to_wait_ms, uint32_t (std::numeric_limits<int32_t >::max ()));
634638
639+ #if CFG_OS_NAME != CFG_OS_NAME_EMSCRIPTEN
635640 if (SDL_WaitEventTimeout (nullptr , int (to_wait_ms)) == 0 ) {
636641 // No events or error. In case of error not much we can do, just ignore it.
637642 return ;
638643 }
644+ #endif
639645
640646 ruis::vector2 new_win_dims (-1 , -1 );
641647
@@ -750,6 +756,13 @@ void main_loop_iteration(void* user_data)
750756 if (new_win_dims.is_positive_or_zero ()) {
751757 update_window_rect (*app, ruis::rect (0 , new_win_dims));
752758 }
759+
760+ #if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
761+ if (ww.quit_flag .load ()){
762+ std::unique_ptr<ruisapp::application> p (app);
763+ emscripten_cancel_main_loop ();
764+ }
765+ #endif
753766}
754767} // namespace
755768
@@ -765,10 +778,11 @@ int main(int argc, const char** argv)
765778#if CFG_OS_NAME == CFG_OS_NAME_EMSCRIPTEN
766779 emscripten_set_main_loop_arg (
767780 &main_loop_iteration,
768- app.get (),
781+ app.release (),
769782 0 ,
770783 false
771784 );
785+ return 0 ;
772786#else
773787 while (!get_impl (*app).quit_flag .load ()) {
774788 main_loop_iteration (app.get ());
0 commit comments