Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

- Cache failed assets by type to allow content loading fallback by type #8

Merged
merged 1 commit into from Aug 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/platform/CCContentManager.cs
Expand Up @@ -77,7 +77,7 @@ public AssetEntry(object asset, string assetFileName, bool weakReference, bool u

Dictionary<string, AssetEntry> loadedAssets;
Dictionary<string, string> assetLookupDict = new Dictionary<string, string>();
Dictionary<string, string> failedAssets = new Dictionary<string, string>();
Dictionary<Tuple<string, Type>, string> failedAssets = new Dictionary<Tuple<string, Type>, string>();

List<string> searchPaths = new List<string>();
List<string> searchResolutionsOrder = new List<string>();
Expand Down Expand Up @@ -180,7 +180,8 @@ string GetRealName(string assetName)

public T TryLoad<T>(string assetName, bool weakReference=false)
{
if (failedAssets.ContainsKey(assetName))
var assetKey = Tuple.Create(assetName, typeof(T));
if (failedAssets.ContainsKey(assetKey))
{
return default(T);
}
Expand All @@ -191,15 +192,16 @@ public T TryLoad<T>(string assetName, bool weakReference=false)
}
catch (Exception)
{
failedAssets[assetName] = null;
failedAssets[assetKey] = null;

return default(T);
}
}

public override T Load<T>(string assetName)
{
if (failedAssets.ContainsKey(assetName))
var assetKey = Tuple.Create(assetName, typeof(T));
if (failedAssets.ContainsKey(assetKey))
{
throw new ContentLoadException("Failed to load the asset file from " + assetName);
}
Expand All @@ -210,7 +212,7 @@ public override T Load<T>(string assetName)
}
catch (Exception)
{
failedAssets[assetName] = null;
failedAssets[assetKey] = null;

throw;
}
Expand Down