Skip to content

Commit d049035

Browse files
committed
[修复]1. 修复数据对象可能为空的处理
1 parent 326c7b1 commit d049035

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

GameFrameX.Core/Components/StateComponent.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static async Task TimerSave()
9090
/// <typeparam name="TState"></typeparam>
9191
public abstract class StateComponent<TState> : BaseComponent, IState where TState : BaseCacheState, new()
9292
{
93-
private static readonly ConcurrentDictionary<long, TState> StateDic = new();
93+
private static readonly ConcurrentDictionary<long, TState> StateDic = new ConcurrentDictionary<long, TState>();
9494

9595
static StateComponent()
9696
{
@@ -137,8 +137,11 @@ public async Task ReadStateAsync()
137137
State = await GameDb.FindAsync<TState>(ActorId);
138138
}
139139

140-
StateDic.TryRemove(State.Id, out _);
141-
StateDic.TryAdd(State.Id, State);
140+
if (State.IsNotNull())
141+
{
142+
StateDic.TryRemove(State.Id, out _);
143+
StateDic.TryAdd(State.Id, State);
144+
}
142145
}
143146

144147
/// <summary>
@@ -169,7 +172,10 @@ internal override async Task SaveState()
169172
{
170173
try
171174
{
172-
await GameDb.UpdateAsync(State);
175+
if (State.IsNotNull())
176+
{
177+
await GameDb.UpdateAsync(State);
178+
}
173179
}
174180
catch (Exception e)
175181
{
@@ -181,9 +187,9 @@ internal override async Task SaveState()
181187
/// 更新状态
182188
/// </summary>
183189
/// <returns></returns>
184-
public Task WriteStateAsync()
190+
public async Task WriteStateAsync()
185191
{
186-
return GameDb.UpdateAsync(State);
192+
await SaveState();
187193
}
188194

189195

0 commit comments

Comments
 (0)