diff --git a/LibDmd/Analytics.cs b/LibDmd/Analytics.cs index 596d6ae54..c95fb5a41 100644 --- a/LibDmd/Analytics.cs +++ b/LibDmd/Analytics.cs @@ -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"); @@ -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); diff --git a/LibDmd/DmdDevice/DmdDevice.cs b/LibDmd/DmdDevice/DmdDevice.cs index 733413759..5100e60e4 100644 --- a/LibDmd/DmdDevice/DmdDevice.cs +++ b/LibDmd/DmdDevice/DmdDevice.cs @@ -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 { diff --git a/LibDmd/Input/MemoryGrabber.cs b/LibDmd/Input/MemoryGrabber.cs index 0c8b5542c..0ee92fdc5 100644 --- a/LibDmd/Input/MemoryGrabber.cs +++ b/LibDmd/Input/MemoryGrabber.cs @@ -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(); }