From 9494885f45bf72475193b4bd357c108be0640ac7 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 19 Aug 2019 12:48:26 +0300 Subject: [PATCH] Do not crash on infs/nans in values, just discard plot --- graphs/data/fitDamageStats/graph.py | 2 +- graphs/gui/canvasPanel.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/graphs/data/fitDamageStats/graph.py b/graphs/data/fitDamageStats/graph.py index da8c48ba1..40b6b4075 100644 --- a/graphs/data/fitDamageStats/graph.py +++ b/graphs/data/fitDamageStats/graph.py @@ -60,8 +60,8 @@ class FitDamageStatsGraph(FitGraph): XDef(handle='tgtSigRad', unit='m', label='Target signature radius', mainInput=('tgtSigRad', '%')), XDef(handle='tgtSigRad', unit='%', label='Target signature radius', mainInput=('tgtSigRad', '%'))] inputs = [ - Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=None, defaultRange=(0, 80), secondaryTooltip='When set, uses attacker\'s exact damage stats at a given time\nWhen not set, uses attacker\'s damage stats as shown in stats panel of main window'), Input(handle='distance', unit='km', label='Distance', iconID=1391, defaultValue=None, defaultRange=(0, 100), mainTooltip='Distance between the attacker and the target, as seen in overview (surface-to-surface)', secondaryTooltip='Distance between the attacker and the target, as seen in overview (surface-to-surface)\nWhen set, places the target that far away from the attacker\nWhen not set, attacker\'s weapons always hit the target'), + Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=None, defaultRange=(0, 80), secondaryTooltip='When set, uses attacker\'s exact damage stats at a given time\nWhen not set, uses attacker\'s damage stats as shown in stats panel of main window'), Input(handle='tgtSpeed', unit='%', label='Target speed', iconID=1389, defaultValue=100, defaultRange=(0, 100)), Input(handle='tgtSigRad', unit='%', label='Target signature', iconID=1390, defaultValue=100, defaultRange=(100, 200), conditions=[ (('tgtSigRad', 'm'), None), diff --git a/graphs/gui/canvasPanel.py b/graphs/gui/canvasPanel.py index 45cb436bd..5485035fc 100644 --- a/graphs/gui/canvasPanel.py +++ b/graphs/gui/canvasPanel.py @@ -19,6 +19,7 @@ import itertools +import math import os import traceback from bisect import bisect @@ -149,6 +150,9 @@ class GraphCanvasPanel(wx.Panel): ySpec=chosenY, src=source, tgt=target) + if not self.__checkNumbers(xs, ys): + pyfalog.warning('Failed to plot "{}" vs "{}" due to inf or NaN in values'.format(source.name, '' if target is None else target.name)) + continue plotData[(source, target)] = (xs, ys) allXs.update(xs) allYs.update(ys) @@ -299,6 +303,13 @@ class GraphCanvasPanel(wx.Panel): y = y1 + pos * (y2 - y1) return y + @staticmethod + def __checkNumbers(xs, ys): + for number in itertools.chain(xs, ys): + if math.isnan(number) or math.isinf(number): + return False + return True + # Matplotlib event handlers def OnMplCanvasClick(self, event): if event.button == 1: