Avoid stack overflow when trying to push a not-yet async loaded background.

This commit is contained in:
Thomas Müller 2016-11-12 18:33:47 +01:00
parent c7f8d2450a
commit 16dc74df5b
2 changed files with 8 additions and 3 deletions

@ -1 +1 @@
Subproject commit 5c0e4edbbcdc26ab56c70676856477cd21e7afdc Subproject commit adb57b048ea874d61fd1822ad3f270ecb67d1e93

View File

@ -43,13 +43,18 @@ private void load(BaseGame game)
public override bool Push(GameMode mode) public override bool Push(GameMode mode)
{ {
//don't actually push until we've finished loading. // When trying to push a non-loaded GameMode, load it asynchronously and re-invoke Push
if (!mode.IsLoaded) // once it's done.
if (mode.LoadState == LoadState.NotLoaded)
{ {
mode.Preload(game, d => Push((BackgroundMode)d)); mode.Preload(game, d => Push((BackgroundMode)d));
return true; return true;
} }
// Make sure the in-progress loading is complete before pushing the GameMode.
while (mode.LoadState < LoadState.Loaded)
Thread.Sleep(1);
base.Push(mode); base.Push(mode);
return true; return true;