fix farmhand crash in some cases when host exits game

This commit is contained in:
Jesse Plamondon-Willard 2018-04-30 22:47:15 -04:00
parent 82ad4cef0d
commit 6221406890
1 changed files with 5 additions and 15 deletions

View File

@ -68,9 +68,6 @@ namespace StardewModdingAPI.Framework
/// <summary>Whether the after-load events were raised for this session.</summary>
private bool RaisedAfterLoadEvent;
/// <summary>Whether the game is returning to the menu.</summary>
private bool IsExitingToTitle;
/// <summary>Whether the game is saving and SMAPI has already raised <see cref="SaveEvents.BeforeSave"/>.</summary>
private bool IsBetweenSaveEvents;
@ -300,11 +297,12 @@ namespace StardewModdingAPI.Framework
if (this.FirstUpdate)
this.OnGameInitialised();
/*********
** Update context
*********/
if (Context.IsSaveLoaded && !SaveGame.IsProcessing /*still loading save*/ && this.AfterLoadTimer >= 0 && Game1.currentLocation != null)
if (Context.IsWorldReady && !Context.IsSaveLoaded)
this.MarkWorldNotReady();
else if (Context.IsSaveLoaded && !SaveGame.IsProcessing /*still loading save*/ && this.AfterLoadTimer >= 0 && Game1.currentLocation != null)
{
if (Game1.dayOfMonth != 0) // wait until new-game intro finishes (world not fully initialised yet)
this.AfterLoadTimer--;
@ -367,17 +365,9 @@ namespace StardewModdingAPI.Framework
/*********
** Exit to title events
*********/
// before exit to title
if (Game1.exitToTitle)
this.IsExitingToTitle = true;
// after exit to title
if (Context.IsWorldReady && this.IsExitingToTitle && Game1.activeClickableMenu is TitleMenu)
{
this.Monitor.Log("Context: returned to title", LogLevel.Trace);
this.IsExitingToTitle = false;
this.CleanupAfterReturnToTitle();
this.Events.Save_AfterReturnToTitle.Raise();
}
@ -1242,8 +1232,8 @@ namespace StardewModdingAPI.Framework
/****
** Methods
****/
/// <summary>Perform any cleanup needed when the player unloads a save and returns to the title screen.</summary>
private void CleanupAfterReturnToTitle()
/// <summary>Perform any cleanup needed when a save is unloaded.</summary>
private void MarkWorldNotReady()
{
Context.IsWorldReady = false;
this.AfterLoadTimer = 5;