emscripten: fix a crash when onvisibilitychange fired during loading

This commit is contained in:
Sebastian Krzyszkowiak 2019-01-10 06:03:57 +01:00
parent 8c7068b48d
commit 871cdf115e
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 8 additions and 1 deletions

View file

@ -217,6 +217,7 @@ struct Game {
int progress;
int loaded, to_load;
volatile bool in_progress;
bool lock;
double time;
ALLEGRO_BITMAP* fb;
} loading;

View file

@ -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) {
ClearGarbage(game);
return MainloopEvents(game) && MainloopTick(game);
if (game->_priv.loading.lock) {
return true;
}
ClearGarbage(game);
return MainloopEvents(game) && MainloopTick(game) && MainloopEvents(game);
}