From 1c7e738ec347a7361ab912491dbb6b4865de4cff Mon Sep 17 00:00:00 2001 From: Nikos Kastellanos Date: Sun, 12 May 2024 12:52:57 +0300 Subject: [PATCH] revert ContentReadersCache Check (#1557) * Revert "move TypeVersion check" This reverts commit aef352cb35a4ce1361afa466d507fe6b3ba542b4. * Revert "simplify _contentReadersCache check" This reverts commit 489450884de3b39d88c45cd3ab22aa8a2800abb6. * Revert "move _contentReadersCache" This reverts commit 5fba42e7a4b29d3008cb5df2fa98ba186146f3f8. --- .../Content/ContentTypeReaderManager.cs | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs b/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs index f0029db4827..4280012e60e 100644 --- a/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs +++ b/src/Xna.Framework.Content/Content/ContentTypeReaderManager.cs @@ -74,33 +74,35 @@ internal ContentTypeReader[] LoadAssetReaders(ContentReader reader, int typeRead int readerTypeVersion = reader.ReadInt32(); ContentTypeReader typeReader; + Type typeReaderType; if (!_contentTypeReadersCache.ContainsKey(readerTypeName)) { - Type typeReaderType = ResolveReaderType(readerTypeName); + typeReaderType = ResolveReaderType(readerTypeName); _contentTypeReadersCache.Add(readerTypeName, typeReaderType); + } + else + { + typeReaderType = _contentTypeReadersCache[readerTypeName]; + } - System.Diagnostics.Debug.Assert(!_contentReadersCache.ContainsKey(typeReaderType)); - + if (!_contentReadersCache.ContainsKey(typeReaderType)) + { typeReader = typeReaderType.GetDefaultConstructor().Invoke(null) as ContentTypeReader; needsInitialize[i] = true; _contentReadersCache.Add(typeReaderType, typeReader); - - if (readerTypeVersion != typeReader.TypeVersion) - { - throw new ContentLoadException( - String.Format("{0} of TypeVersion {1} does not match reader of TypeVersion {2}.", - typeReader.TargetType.Name, readerTypeVersion, typeReader.TypeVersion)); - } } else { - Type typeReaderType = _contentTypeReadersCache[readerTypeName]; - - System.Diagnostics.Debug.Assert(_contentReadersCache.ContainsKey(typeReaderType)); - typeReader = _contentReadersCache[typeReaderType]; } + if (readerTypeVersion != typeReader.TypeVersion) + { + throw new ContentLoadException( + String.Format("{0} of TypeVersion {1} does not match reader of TypeVersion {2}.", + typeReader.TargetType.Name, readerTypeVersion, typeReader.TypeVersion)); + } + contentReaders[i] = typeReader;