check _cts before building/removing world objects

This commit is contained in:
JohnCorby 2022-01-28 21:17:59 -08:00
parent 8a67003196
commit d706ffd998

View File

@ -33,6 +33,11 @@ namespace QSB.WorldSync
public static async UniTaskVoid BuildWorldObjects(OWScene scene)
{
if (_cts != null)
{
return;
}
_cts = new CancellationTokenSource();
if (!PlayerTransformSync.LocalInstance)
@ -79,13 +84,20 @@ namespace QSB.WorldSync
public static void RemoveWorldObjects()
{
_cts?.Cancel();
_cts?.Dispose();
_managerTasks.Clear();
_objectTasks.Clear();
if (_cts == null)
{
return;
}
_cts.Cancel();
_cts.Dispose();
_cts = null;
GameReset();
_managerTasks.Clear();
_objectTasks.Clear();
foreach (var item in WorldObjects)
{
item.Try("removing", item.OnRemoval);