From 1a1b72105e24f6d4bde0d5ee7526668ab6ebfa28 Mon Sep 17 00:00:00 2001 From: hyperion51 Date: Fri, 27 Mar 2020 16:46:46 +0000 Subject: [PATCH] Fix empty cache get Fixed exception in DatabaseCache when attempting to get entry types which haven't been added --- Assets/Scripts/ServerShared/DatabaseCache.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/ServerShared/DatabaseCache.cs b/Assets/Scripts/ServerShared/DatabaseCache.cs index b89b12724..9ca24bc12 100644 --- a/Assets/Scripts/ServerShared/DatabaseCache.cs +++ b/Assets/Scripts/ServerShared/DatabaseCache.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; @@ -66,6 +67,8 @@ public class DatabaseCache public T Get(Guid guid) where T : DatabaseEntry { + if (!_types.ContainsKey(typeof(T))) + return null; DatabaseEntry entry; _types[typeof(T)].TryGetValue(guid, out entry); return (T) entry; @@ -73,7 +76,7 @@ public class DatabaseCache public IEnumerable GetAll() { - return _types[typeof(T)].Values.Cast(); + return !_types.ContainsKey(typeof(T)) ? Enumerable.Empty() : _types[typeof(T)].Values.Cast(); } public void Delete(DatabaseEntry entry, bool remote = false)