Skip to content

Commit

Permalink
Improve Mumble error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Sep 16, 2023
1 parent a31db14 commit 60471d9
Showing 1 changed file with 45 additions and 10 deletions.
55 changes: 45 additions & 10 deletions GW2SDK/GameLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,67 @@ private void Publish()
{
if (subscribers.Count == 0)
{
// Not sure if this is possible, the timer only starts after someone subscribes
return;
}

GameTick tick;
try
{
var snapshot = GetSnapshot();
if (snapshot.UiTick != lastTick)
tick = GetSnapshot();
}
catch (Exception reason)
{
// Notify every observer that there has been an internal error
foreach (var subscriber in subscribers.ToList())
{
lastTick = snapshot.UiTick;
foreach (var subscriber in subscribers.ToList())
try
{
subscriber.OnNext(snapshot);
subscriber.OnError(reason);
}
catch
{
// They did not respond well to the bad news
}
}

timer.Start();
subscribers.Clear();
return;
}
catch (Exception reason)

// The timer can be faster than the refresh rate of the shared memory
// so ensure that the UiTick has changed, to avoid sending duplicates
// This is especially important during loading screens or character selection
if (tick.UiTick != lastTick)
{
lastTick = tick.UiTick;
foreach (var subscriber in subscribers.ToList())
{
subscriber.OnError(reason);
try
{
subscriber.OnNext(tick);
}
catch (Exception reason)
{
// The observer threw an unhandled exception, which an observer should never do
try
{
// Notify them of their own error and then unsubscribe them
subscriber.OnError(reason);
}
catch
{
// At least we tried the diplomatic approach but they chose violence
}
finally
{
subscribers.Remove(subscriber);
}
}
}

subscribers.Clear();
}

timer.Start();
}

#if NET
Expand Down

0 comments on commit 60471d9

Please sign in to comment.