From 8613dc3321b9978a4f2f119c37f779d1212d5ec8 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 12 Sep 2024 04:05:15 +0800 Subject: [PATCH] fix debug service --- src/DebugUtils/EcsDebug.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/DebugUtils/EcsDebug.cs b/src/DebugUtils/EcsDebug.cs index 0356dcc..d87ac8f 100644 --- a/src/DebugUtils/EcsDebug.cs +++ b/src/DebugUtils/EcsDebug.cs @@ -12,7 +12,10 @@ namespace DCFApixels.DragonECS { public readonly int id; internal EcsProfilerMarker(int id) { this.id = id; } - public EcsProfilerMarker(string name) { id = DebugService.Instance.RegisterMark(name); } + public EcsProfilerMarker(string name) + { + id = DebugService.Instance.RegisterMark(name); + } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Begin() { DebugService.Instance.ProfilerMarkBegin(id); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -169,7 +172,7 @@ namespace DCFApixels.DragonECS var oldService = _instance; _instance = service; if(_instance != null) - { //TODO Так, всеже треды влияют друг на друга, скоерее всего проблема в использовании _nameIdTable + { //TODO Так, всеже треды влияют друг на друга, скоерее всего проблема в использовании _nameIdTable/ Так вроде пофиксил, но не понял как конкретно foreach (var info in oldService.MarkerInfos) { service._idDispenser.Use(info.ID); @@ -187,7 +190,7 @@ namespace DCFApixels.DragonECS public static Action OnServiceChanged = delegate { }; private IdDispenser _idDispenser = new IdDispenser(16, 0); - private ConcurrentDictionary _nameIdTable = new ConcurrentDictionary(); + private Dictionary _nameIdTable = new Dictionary(); public abstract void Print(string tag, object v); public abstract void Break(); public int RegisterMark(string name) @@ -197,11 +200,14 @@ namespace DCFApixels.DragonECS { lock (_lock) { - id = _idDispenser.UseFree(); - _nameIdTable.TryAdd(name, id); + if (!_nameIdTable.TryGetValue(name, out id)) + { + id = _idDispenser.UseFree(); + _nameIdTable.Add(name, id); + OnNewProfilerMark(id, name); + } } } - OnNewProfilerMark(id, name); return id; } public void DeleteMark(string name) @@ -210,7 +216,7 @@ namespace DCFApixels.DragonECS { int id = _nameIdTable[name]; //TODO проверить TryRemove - _nameIdTable.TryRemove(name, out id); + _nameIdTable.Remove(name); _idDispenser.Release(id); OnDelProfilerMark(id); }