Skip to content

Commit

Permalink
Check if GraphPane is null before attempting to modify CurveList
Browse files Browse the repository at this point in the history
  • Loading branch information
ncguilbeault committed Apr 19, 2024
1 parent 11b4197 commit 54bee01
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions src/Bonsai.Gui.ZedGraph/BoundedGraphPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,50 +41,53 @@ public int Capacity

protected override void OnInvalidated(InvalidateEventArgs e)
{
double? maxValue = null;
var curveList = GraphPane.CurveList;
for (int i = 0; i < curveList.Count; i++)
if (!(GraphPane is null))
{
if (curveList[i].Points is BoundedPointPairList boundedList)
double? maxValue = null;
var curveList = GraphPane.CurveList;
for (int i = 0; i < curveList.Count; i++)
{
if (span <= 0)
{
boundedList.SetBounds(double.MinValue, double.MaxValue);
}
else if (boundedList.Count > 0)
if (curveList[i].Points is BoundedPointPairList boundedList)
{
maxValue = Math.Max(
maxValue.GetValueOrDefault(double.MinValue),
boundedList[boundedList.Count - 1].Z);
if (span <= 0)
{
boundedList.SetBounds(double.MinValue, double.MaxValue);
}
else if (boundedList.Count > 0)
{
maxValue = Math.Max(
maxValue.GetValueOrDefault(double.MinValue),
boundedList[boundedList.Count - 1].Z);
}
}
}
}

if (maxValue != null)
{
var lowerBound = maxValue.GetValueOrDefault() - span;
for (int i = 0; i < curveList.Count; i++)
if (maxValue != null)
{
if (curveList[i].Points is BoundedPointPairList boundedList)
var lowerBound = maxValue.GetValueOrDefault() - span;
for (int i = 0; i < curveList.Count; i++)
{
boundedList.SetBounds(lowerBound, double.MaxValue);
if (curveList[i].Points is BoundedPointPairList boundedList)
{
boundedList.SetBounds(lowerBound, double.MaxValue);
}
}
}
}

if (setCapacity != null)
{
for (int i = 0; i < curveList.Count; i++)
if (setCapacity != null)
{
if (curveList[i].Points is BoundedPointPairList boundedList)
for (int i = 0; i < curveList.Count; i++)
{
boundedList.SetCapacity(capacity);
if (curveList[i].Points is BoundedPointPairList boundedList)
{
boundedList.SetCapacity(capacity);
}
}
}

setCapacity = null;
setCapacity = null;
}
}

base.OnInvalidated(e);
}

Expand Down

0 comments on commit 54bee01

Please sign in to comment.