From 8cf356cadb98a69be7c50d25c9fe72c7948e1a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Tue, 14 Jan 2025 16:03:24 +0800 Subject: [PATCH] fix #447 --- .../AssetDependencyDatabase.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs index 50aea16c..3a4f970f 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetDependencyDatabase.cs @@ -40,13 +40,15 @@ namespace YooAsset.Editor _databaseFilePath = databaseFilePath; _database.Clear(); + FileStream stream = null; + BinaryReader reader = null; try { if (readCacheDatabaseFile && File.Exists(databaseFilePath)) { // 解析缓存文件 - using var stream = File.OpenRead(databaseFilePath); - using var reader = new BinaryReader(stream); + stream = File.OpenRead(databaseFilePath); + reader = new BinaryReader(stream); string fileVersion = reader.ReadString(); if (fileVersion != FILE_VERSION) throw new Exception("The database file version not match !"); @@ -85,6 +87,13 @@ namespace YooAsset.Editor ClearDatabase(true); Debug.LogError($"Failed to load cache database : {ex.Message}"); } + finally + { + if (reader != null) + reader.Close(); + if (stream != null) + stream.Close(); + } // 查找新增或变动资源 var allAssetPaths = AssetDatabase.GetAllAssetPaths(); @@ -114,10 +123,12 @@ namespace YooAsset.Editor if (File.Exists(_databaseFilePath)) File.Delete(_databaseFilePath); + FileStream stream = null; + BinaryWriter writer = null; try { - using var stream = File.Create(_databaseFilePath); - using var writer = new BinaryWriter(stream); + stream = File.Create(_databaseFilePath); + writer = new BinaryWriter(stream); writer.Write(FILE_VERSION); writer.Write(_database.Count); foreach (var assetPair in _database) @@ -134,6 +145,13 @@ namespace YooAsset.Editor { Debug.LogError($"Failed to save cache database : {ex.Message}"); } + finally + { + if (writer != null) + writer.Close(); + if (stream != null) + stream.Close(); + } } ///