Skip to content

SignalXY: Index was outside the bounds of the array #3926

@githubkau

Description

@githubkau

It can be reproduced when there is only one value in the plot and you select a rectangle with the middle mouse button.

5.0.34

SignalXY Plot with 4 signals and an additional right hand side y-axis and a DateTime x-Axis

Index was outside the bounds of the array.
   at ScottPlot.DataSources.SignalXYSourceDoubleArray.GetFirstPointX(IAxes axes)
   at ScottPlot.DataSources.SignalXYSourceDoubleArray.GetPixelsToDrawHorizontally(RenderPack rp, IAxes axes)
   at ScottPlot.Plottables.SignalXY.Render(RenderPack rp)
   at ScottPlot.Rendering.RenderActions.RenderPlottables.Render(RenderPack rp)
   at ScottPlot.Rendering.RenderManager.Render(SKCanvas canvas, PixelRect rect)
   at ScottPlot.Plot.Render(SKCanvas canvas, PixelRect rect)
   at SkiaSharp.Views.WPF.SKElement.OnRender(DrawingContext drawingContext)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

It can be reproduced when there is only one value in the plot and you select a rectangle with the middle mouse button.

It might be solved by changing SignalXYSourceDoubleArray.cs in line 243 from firstPointPosition to firstIndex (see below).

/// <summary>
/// If data is off to the screen to the left, 
/// returns information about the closest point off the screen
/// </summary>
private (Pixel[] pointsBefore, int firstIndex) GetFirstPointX(IAxes axes)
{
    var (firstPointPosition, firstPointIndex) = SearchIndex(axes.XAxis.Range.Span > 0 ? axes.XAxis.Min : axes.XAxis.Max); // if axis is reversed first index will on the right limit of the plot

    if (firstPointIndex > MinimumIndex)
    {
        float beforeX = axes.GetPixelX(Xs[firstPointIndex - 1] + XOffset);
        float beforeY = axes.GetPixelY(Ys[firstPointIndex - 1] * YScale + YOffset);
        Pixel beforePoint = new(beforeX, beforeY);
        return ([beforePoint], firstPointIndex);
    }
    else
    {
        return ([], MinimumIndex);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions