fix errors caused by content managers finalizing asynchronously
This commit is contained in:
parent
29232ffd45
commit
bd4ed43829
|
@ -127,10 +127,13 @@ namespace StardewModdingAPI.Framework
|
|||
/// <summary>Get whether the content manager has already loaded and cached the given asset.</summary>
|
||||
/// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
|
||||
public bool IsLoaded(string assetName)
|
||||
{
|
||||
lock (this.Cache)
|
||||
{
|
||||
assetName = this.NormaliseAssetName(assetName);
|
||||
return this.IsNormalisedKeyLoaded(assetName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Load an asset that has been processed by the content pipeline.</summary>
|
||||
/// <typeparam name="T">The type of asset to load.</typeparam>
|
||||
|
@ -145,6 +148,8 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
|
||||
/// <param name="instance">The content manager instance for which to load the asset.</param>
|
||||
public T LoadFor<T>(string assetName, ContentManager instance)
|
||||
{
|
||||
lock (this.Cache)
|
||||
{
|
||||
assetName = this.NormaliseAssetName(assetName);
|
||||
|
||||
|
@ -179,17 +184,21 @@ namespace StardewModdingAPI.Framework
|
|||
this.TrackAssetLoader(assetName, instance);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Inject an asset into the cache.</summary>
|
||||
/// <typeparam name="T">The type of asset to inject.</typeparam>
|
||||
/// <param name="assetName">The asset path relative to the loader root directory, not including the <c>.xnb</c> extension.</param>
|
||||
/// <param name="value">The asset value.</param>
|
||||
public void Inject<T>(string assetName, T value)
|
||||
{
|
||||
lock (this.Cache)
|
||||
{
|
||||
assetName = this.NormaliseAssetName(assetName);
|
||||
this.Cache[assetName] = value;
|
||||
this.TrackAssetLoader(assetName, this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Get the current content locale.</summary>
|
||||
public string GetLocale()
|
||||
|
@ -199,6 +208,8 @@ namespace StardewModdingAPI.Framework
|
|||
|
||||
/// <summary>Get the cached asset keys.</summary>
|
||||
public IEnumerable<string> GetAssetKeys()
|
||||
{
|
||||
lock (this.Cache)
|
||||
{
|
||||
IEnumerable<string> GetAllAssetKeys()
|
||||
{
|
||||
|
@ -211,6 +222,7 @@ namespace StardewModdingAPI.Framework
|
|||
|
||||
return GetAllAssetKeys().Distinct();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Purge assets from the cache that match one of the interceptors.</summary>
|
||||
/// <param name="editors">The asset editors for which to purge matching assets.</param>
|
||||
|
@ -247,6 +259,8 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param>
|
||||
/// <returns>Returns whether any cache entries were invalidated.</returns>
|
||||
public bool InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
|
||||
{
|
||||
lock (this.Cache)
|
||||
{
|
||||
// find matching asset keys
|
||||
HashSet<string> purgeCacheKeys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
|
||||
|
@ -288,6 +302,7 @@ namespace StardewModdingAPI.Framework
|
|||
this.Monitor.Log("Invalidated 0 cache entries.", LogLevel.Trace);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Dispose assets for the given content manager shim.</summary>
|
||||
/// <param name="shim">The content manager whose assets to dispose.</param>
|
||||
|
|
Loading…
Reference in New Issue