fix: OnDisable 加 GC.Collect+WaitForPendingFinalizers 防 SQLite 析构崩溃

- sqlite-net PreparedSqlLiteInsertCommand 析构器在 GC 线程跑 sqlite3_finalize
- Domain reload 时 SQLite native 可能已卸载 → 崩溃
- GC.Collect+WaitForPendingFinalizers 确保析构器在 native 还活着时完成
This commit is contained in:
tian 2026-06-13 12:24:09 +08:00
parent a39439c023
commit 5c23e92587
6 changed files with 5 additions and 5 deletions

View File

@ -22,7 +22,7 @@ namespace CounterDrone.Unity
_service = new GroupService(new GroupRepository(_db));
}
void OnDisable() { _db?.Dispose(); _db = null; }
void OnDisable() { _db?.Dispose(); _db = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public Group Create(string name, GroupType type, string desc = "")
=> _service.CreateGroup(name, type, desc);

View File

@ -24,7 +24,7 @@ namespace CounterDrone.Unity
_service = new ModelService(new ModelRepository(_db), _paths);
}
void OnDisable() { _db?.Dispose(); _db = null; }
void OnDisable() { _db?.Dispose(); _db = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public ModelInfo Import(string filePath, string name) => _service.ImportModel(filePath, name);
public void Delete(string id) => _service.DeleteModel(id);

View File

@ -22,7 +22,7 @@ namespace CounterDrone.Unity
_service = new ReportService(_db, _paths);
}
void OnDisable() { _db?.Dispose(); _db = null; }
void OnDisable() { _db?.Dispose(); _db = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public SimulationReport Generate(string taskId, TaskFullConfig cfg, List<SimEvent> events, string status, float duration)
=> _service.Generate(taskId, cfg, events, status, duration);

View File

@ -35,7 +35,7 @@ namespace CounterDrone.Unity
}
}
void OnDisable() { _db?.Dispose(); _db = null; }
void OnDisable() { _db?.Dispose(); _db = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
public SimTask CreateTask(string name, string number) => _service.CreateTask(name, number);
public void DeleteTask(string id) => _service.DeleteTask(id);

View File

@ -149,7 +149,7 @@ namespace CounterDrone.Unity
}
public void Stop() => _engine?.Stop();
void OnDisable() { _db?.Dispose(); _db = null; }
void OnDisable() { _db?.Dispose(); _db = null; GC.Collect(); GC.WaitForPendingFinalizers(); }
void OnDestroy() => Stop();
private void SpawnDroneVisual(DroneEntity drone)