Skip to content

Commit 4cfd14b

Browse files
committed
fixe reentrancy bug (v3.5.1)
1 parent f052e4e commit 4cfd14b

13 files changed

Lines changed: 548 additions & 339 deletions

File tree

Assets/OxGFrame/AssetLoader/Scripts/Runtime/Bundle/PatchManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,6 @@ public PatchManager()
145145
this._patchFsm.AddNode<PatchFsmStates.FsmPatchDone>();
146146
}
147147

148-
~PatchManager()
149-
{
150-
this.Cancel();
151-
this._userEvents.RemoveAllListener();
152-
this._patchFsm = null;
153-
}
154-
155148
#region Patch Operation
156149
/// <summary>
157150
/// 開啟檢查流程
Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using OxGKit.LoggingSystem;
2+
using System.Collections.Generic;
23

34
namespace OxGFrame.AssetLoader.Cacher
45
{
@@ -9,29 +10,22 @@ internal abstract class AssetCache<T>
910
/// </summary>
1011
public class RetryCounter
1112
{
12-
public byte retryCount;
13-
public byte maxRetryCount;
13+
public int retryCount;
14+
public int maxRetryCount;
1415

15-
public RetryCounter(byte maxRetryCount)
16+
public RetryCounter(int maxRetryCount)
1617
{
17-
this.retryCount = 0;
18-
this.maxRetryCount = maxRetryCount;
18+
this.retryCount = this.maxRetryCount = maxRetryCount;
1919
}
2020

21-
public bool IsRetryActive()
21+
public bool IsOutOfRetries()
2222
{
23-
return this.retryCount > 0;
23+
return this.retryCount < 0;
2424
}
2525

26-
public bool IsRetryValid()
26+
public void DelRetryCount()
2727
{
28-
// 嘗試次數先++, 後判斷, 所以需使用 <= 進行判斷
29-
return this.retryCount <= maxRetryCount;
30-
}
31-
32-
public void AddRetryCount()
33-
{
34-
this.retryCount++;
28+
this.retryCount--;
3529
}
3630
}
3731

@@ -41,9 +35,14 @@ public void AddRetryCount()
4135
protected Dictionary<string, T> _cacher;
4236

4337
/// <summary>
44-
/// Blocker 加載標記
38+
/// Blocker 加載標記緩存
4539
/// </summary>
46-
protected Dictionary<string, RetryCounter> _loadingFlags;
40+
protected HashSet<string> _loadingFlags;
41+
42+
/// <summary>
43+
/// 嘗試計數器緩存
44+
/// </summary>
45+
protected Dictionary<string, RetryCounter> _retryCounters;
4746

4847
/// <summary>
4948
/// 當前進度數量 (Progress)
@@ -67,40 +66,55 @@ public void AddRetryCount()
6766
public AssetCache()
6867
{
6968
this._cacher = new Dictionary<string, T>();
70-
this._loadingFlags = new Dictionary<string, RetryCounter>();
69+
this._loadingFlags = new HashSet<string>();
70+
this._retryCounters = new Dictionary<string, RetryCounter>();
7171
}
7272

73-
protected bool HasInLoadingFlags(string assetName)
73+
#region Loading Flag
74+
protected bool HasInLoadingFlag(string assetName)
7475
{
7576
if (string.IsNullOrEmpty(assetName))
7677
return false;
77-
return this._loadingFlags.ContainsKey(assetName);
78+
return this._loadingFlags.Contains(assetName);
7879
}
7980

80-
protected void AddLoadingFlags(string assetName, byte maxRetryCount)
81+
protected void AddLoadingFlag(string assetName)
8182
{
82-
if (!this.HasInLoadingFlags(assetName))
83-
this._loadingFlags.Add(assetName, new RetryCounter(maxRetryCount));
83+
if (!this.HasInLoadingFlag(assetName))
84+
{
85+
this._loadingFlags.Add(assetName);
86+
Logging.Print<Logger>($"Marked asset as loading: {assetName}.");
87+
}
8488
}
8589

86-
protected void RemoveLoadingFlags(string assetName)
90+
protected void RemoveLoadingFlag(string assetName)
8791
{
88-
if (this.HasInLoadingFlags(assetName))
92+
if (this.HasInLoadingFlag(assetName))
93+
{
8994
this._loadingFlags.Remove(assetName);
95+
Logging.Print<Logger>($"Cleared loading flag: {assetName}.");
96+
}
97+
}
98+
#endregion
99+
100+
#region Retry Counter
101+
protected void StartRetryCounter(string assetName, byte maxRetryCount)
102+
{
103+
if (!this._retryCounters.ContainsKey(assetName))
104+
this._retryCounters.Add(assetName, new RetryCounter(maxRetryCount));
90105
}
91106

92107
protected RetryCounter GetRetryCounter(string assetName)
93108
{
94-
this._loadingFlags.TryGetValue(assetName, out RetryCounter retryCounter);
109+
this._retryCounters.TryGetValue(assetName, out RetryCounter retryCounter);
95110
return retryCounter;
96111
}
97112

98-
~AssetCache()
113+
protected void StopRetryCounter(string assetName)
99114
{
100-
this._cacher.Clear();
101-
this._cacher = null;
102-
this._loadingFlags.Clear();
103-
this._loadingFlags = null;
115+
if (this._retryCounters.ContainsKey(assetName))
116+
this._retryCounters.Remove(assetName);
104117
}
118+
#endregion
105119
}
106120
}

Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetObject.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ public T GetAsset<T>() where T : Object
6666
return default;
6767
return this.asset as T;
6868
}
69-
70-
~ResourcePack()
71-
{
72-
this.assetName = null;
73-
this.asset = null;
74-
}
7569
}
7670
#endregion
7771

@@ -208,12 +202,6 @@ public void UnloadAsset()
208202
this.GetOperationHandle<AssetHandle>().Release();
209203
}
210204
#endregion
211-
212-
~BundlePack()
213-
{
214-
this.assetName = null;
215-
this.operationHandle = null;
216-
}
217205
}
218206
#endregion
219207
}

0 commit comments

Comments
 (0)