Skip to content

Commit

Permalink
fix: Don't crash when ending game with segment displays.
Browse files Browse the repository at this point in the history
  • Loading branch information
freezy committed May 19, 2023
1 parent fc7e72e commit 81ee608
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions LibDmd/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ public void StartGame()

public void SetSource(string source, string gameId)
{
StartTimer();
try {
StartTimer();
} catch (Exception e) {
Logger.Warn(e, "Failed to start timer.");
}
_data["Host"] = source;
_data["Game"] = gameId;
}

public void SetSource(string host)
{
StartTimer();
try {
StartTimer();
} catch (Exception e) {
Logger.Warn(e, "Failed to start timer.");
}
_data["Host"] = host;
if (_data.ContainsKey("Game")) {
_data.Remove("Game");
Expand Down Expand Up @@ -135,7 +143,7 @@ public void EndGame()
}
var duration = Math.Round((DateTime.Now - _gameStartedAt).TotalSeconds);
_data["Duration"] = duration;
_data["Weight"] = 1 / _displays.Count;
_data["Weight"] = 1 / (_displays.Count == 0 ? 1 : _displays.Count);
foreach (var display in _displays) {
_data["Display"] = display;
RudderAnalytics.Client.Track(GetId(), "Game Ended", _data, _options);
Expand Down
6 changes: 5 additions & 1 deletion LibDmd/DmdDevice/DmdDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ private void SetVirtualDmdDefaultPosition(double x = -1d, double y = -1d, double
public void Close()
{
Logger.Info("Closing up.");
Analytics.Instance.EndGame();
try {
Analytics.Instance.EndGame();
} catch (Exception e) {
Logger.Warn(e, "Could not end game.");
}
_graphs.ClearDisplay();
_graphs.Dispose();
try {
Expand Down
8 changes: 6 additions & 2 deletions LibDmd/Input/MemoryGrabber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ private void StopCapturing()
Logger.Info($"Terminating DMD data capture from {Name}");
_capturer.Dispose();
_onPause.OnNext(Unit.Default);
Analytics.Instance.EndGame();
Analytics.Instance.ClearSource();
try {
Analytics.Instance.EndGame();
Analytics.Instance.ClearSource();
} catch (Exception e) {
Logger.Warn(e, "Error while ending game");
}
StartPolling();
}

Expand Down

0 comments on commit 81ee608

Please sign in to comment.