Skip to content

SignalXY: Fix bug where extrapolated pixel location could be infinity and crash GDI#1806

Merged
swharden merged 5 commits intoScottPlot:mainfrom
StendProg:SignalXYPointBeforeBug1803Fix
Apr 28, 2022
Merged

SignalXY: Fix bug where extrapolated pixel location could be infinity and crash GDI#1806
swharden merged 5 commits intoScottPlot:mainfrom
StendProg:SignalXYPointBeforeBug1803Fix

Conversation

@StendProg
Copy link
Contributor

Purpose:
Fix for #1803

SignalXY in some cases, due to rounding errors when converting to PointF, the PointBefore has the same x coordinate as the first drawn point. As a result, interpolation between these points results in an Overflow Exception. Although ScottPlot catches this exception and continues to work, it becomes impossible to display SignalXY.

Since interpolation between these points was introduced for only one reason - GDI does not correctly draw points with strongly negative coordinates. In our case, the error occurs when both points have a coordinate close to 0. Therefore, this fix simply skips interpolation if the x coordinates are equal, because it is definitely not needed in this case.

I decided to keep the test that I used to reproduce the error, but it can be safely removed, because it can only be useful for manual debugging.

Overflows are commonly thrown by GDI (so they are typically ignored), but an overflow may result in a plottable not being rendered, so it is helpful to enable this exception during debugging. ScottPlot#1803 ScottPlot#1808
@swharden swharden changed the title Fix #1803 SignalXY: Fix bug where extrapolated pixel location could be infinity and crash GDI Apr 28, 2022
@swharden
Copy link
Member

@StendProg, thank you so much for figuring this out! I really appreciate your work on this PR.

...interpolation between these points results in an Overflow Exception. Although ScottPlot catches this exception and continues to work, it becomes impossible to display SignalXY

I added an option to throw this exception, hopefully making debugging easier in the future.

plt.GetSettings(false).IgnoreOverflowExceptionsDuringRender = false;

Throwing exceptions while drawing lines with large pixel coordinate values seems like a GDI-specific issue, so a lot of this complexity may disappear when we switch to SkiaSharp and/or Maui.Graphics 🤞

@swharden swharden linked an issue Apr 28, 2022 that may be closed by this pull request
@swharden swharden enabled auto-merge April 28, 2022 23:38
@swharden swharden merged commit 49c455f into ScottPlot:main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SignalXY sometimes not rendered on high density data

2 participants