fix thread safety for ecsdebug

This commit is contained in:
Mikhail 2024-09-10 19:18:46 +08:00
parent 7cf6894476
commit f2ffc284f9

View File

@ -124,7 +124,10 @@ namespace DCFApixels.DragonECS
{ {
if (_instance == null) if (_instance == null)
{ {
_instance = new DefaultDebugService(); lock (_lock)
{
_instance = new DefaultDebugService();
}
} }
return _instance; return _instance;
} }
@ -132,12 +135,18 @@ namespace DCFApixels.DragonECS
public static void Set<T>() where T : DebugService, new() public static void Set<T>() where T : DebugService, new()
{ {
Set(new T()); lock (_lock)
{
Set(new T());
}
} }
public static void Set(DebugService service) public static void Set(DebugService service)
{ {
_instance = service; lock (_lock)
OnServiceChanged(_instance); {
_instance = service;
OnServiceChanged(_instance);
}
} }
public static Action<DebugService> OnServiceChanged = delegate { }; public static Action<DebugService> OnServiceChanged = delegate { };
@ -162,11 +171,14 @@ namespace DCFApixels.DragonECS
} }
public void DeleteMark(string name) public void DeleteMark(string name)
{ {
int id = _nameIdTable[name]; lock (_lock)
//TODO кажется этот TryRemove не подходит {
_nameIdTable.TryRemove(name, out id); int id = _nameIdTable[name];
_idDispenser.Release(id); //TODO проверить TryRemove
OnDelProfilerMark(id); _nameIdTable.TryRemove(name, out id);
_idDispenser.Release(id);
OnDelProfilerMark(id);
}
} }
protected abstract void OnNewProfilerMark(int id, string name); protected abstract void OnNewProfilerMark(int id, string name);