From 871cdf115e41d287ebf9402e882135b503a45351 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 10 Jan 2019 06:03:57 +0100 Subject: [PATCH] emscripten: fix a crash when onvisibilitychange fired during loading --- src/libsuperderpy.h | 1 + src/mainloop.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libsuperderpy.h b/src/libsuperderpy.h index b9d90fa..80e8539 100644 --- a/src/libsuperderpy.h +++ b/src/libsuperderpy.h @@ -217,6 +217,7 @@ struct Game { int progress; int loaded, to_load; volatile bool in_progress; + bool lock; double time; ALLEGRO_BITMAP* fb; } loading; diff --git a/src/mainloop.c b/src/mainloop.c index 54baa91..874ac2a 100644 --- a/src/mainloop.c +++ b/src/mainloop.c @@ -245,6 +245,7 @@ static inline bool MainloopTick(struct Game* game) { game->_priv.loading.to_load = 0; game->_priv.loading.loaded = 0; + game->_priv.loading.lock = true; game->loading.progress = 0; // TODO: support gamestate dependences/ordering @@ -407,6 +408,8 @@ static inline bool MainloopTick(struct Game* game) { tmp = tmp->next; } + game->_priv.loading.lock = false; + if (!gameActive) { PrintConsole(game, "No gamestates left, exiting..."); return false; @@ -438,6 +441,9 @@ static inline bool MainloopTick(struct Game* game) { } SYMBOL_EXPORT bool libsuperderpy_mainloop(struct Game* game) { + if (game->_priv.loading.lock) { + return true; + } ClearGarbage(game); - return MainloopEvents(game) && MainloopTick(game); + return MainloopEvents(game) && MainloopTick(game) && MainloopEvents(game); }