more potential crash fixes + gpose fix

This commit is contained in:
rootdarkarchon
2023-02-15 23:51:55 +01:00
parent eed44f090d
commit 6457a1fe9a
9 changed files with 94 additions and 61 deletions

View File

@@ -56,43 +56,59 @@ public class GameObjectHandler : MediatorSubscriberBase
});
}
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) =>
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate());
Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) => ZoneSwitchEnd());
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => ZoneSwitchStart());
Mediator.Subscribe<CutsceneStartMessage>(this, (_) =>
{
if (_delayedZoningTask?.IsCompleted ?? true)
Mediator.Unsubscribe<ZoneSwitchStartMessage>(this);
Mediator.Unsubscribe<FrameworkUpdateMessage>(this);
});
Mediator.Subscribe<CutsceneEndMessage>(this, (_) =>
{
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) => ZoneSwitchStart());
Mediator.Subscribe<FrameworkUpdateMessage>(this, (_) => FrameworkUpdate());
});
}
private void FrameworkUpdate()
{
if (_delayedZoningTask?.IsCompleted ?? true)
{
CheckAndUpdateObject();
}
}
private void ZoneSwitchEnd()
{
if (!_sendUpdates) return;
_clearCts?.Cancel();
_clearCts?.Dispose();
_clearCts = null;
_zoningCts.CancelAfter(2500);
}
private void ZoneSwitchStart()
{
if (!_sendUpdates) return;
_zoningCts = new();
Logger.Debug("Starting Delay After Zoning for " + ObjectKind + " " + Name);
_delayedZoningTask = Task.Run(async () =>
{
try
{
CheckAndUpdateObject();
await Task.Delay(TimeSpan.FromSeconds(120), _zoningCts.Token).ConfigureAwait(false);
}
});
Mediator.Subscribe<ZoneSwitchEndMessage>(this, (_) =>
{
if (!watchedObject) return;
_clearCts?.Cancel();
_clearCts?.Dispose();
_clearCts = null;
_zoningCts.CancelAfter(2500);
});
Mediator.Subscribe<ZoneSwitchStartMessage>(this, (_) =>
{
if (!watchedObject) return;
_zoningCts = new();
Logger.Debug("Starting Delay After Zoning for " + ObjectKind + " " + Name);
_delayedZoningTask = Task.Run(async () =>
catch { }
finally
{
try
{
await Task.Delay(TimeSpan.FromSeconds(120), _zoningCts.Token).ConfigureAwait(false);
}
catch { }
finally
{
Logger.Debug("Delay complete for " + ObjectKind);
_zoningCts.Dispose();
}
});
Logger.Debug("Delay complete for " + ObjectKind);
_zoningCts.Dispose();
}
});
}