-
Notifications
You must be signed in to change notification settings - Fork 981
Description
Bug Report
Issue: an "OutOfMemoryException" is fired whenever the SweepAngle property in any of the gauges's is equal or below 0.01.
Explanation: according to this post it seems that DrawArc doesn't handle very well the combination of pen width and small sweep angles.
ScottPlot/src/ScottPlot/Plottable/RadialGauge.cs
Lines 152 to 159 in 6c1a998
| gfx.DrawArc( | |
| pen, | |
| (center.X - radius), | |
| (center.Y - radius), | |
| (radius * 2), | |
| (radius * 2), | |
| (float)StartAngle, | |
| (float)SweepAngle); |
Reproducing: using these values, the DrawArc function fails for sweep angles equal of below 0.01. However, using less values (less gauges, which result in a wider pen width does modify the 0.01 threshold limit.
var plt = new ScottPlot.Plot(600, 400);
double[] values = { 505, 590, 0.005, 0.005, 0.0005, 0.005, 0.005, 0.0005 };
plt.AddRadialGauge(values);Solution: either check for values lower than 0.01 when creating the plot's RadialGauge instances
ScottPlot/src/ScottPlot/Plottable/RadialGaugePlot.cs
Lines 289 to 308 in 6c1a998
| RadialGauge gauge = new() | |
| { | |
| MaximumSizeAngle = MaximumAngle, | |
| StartAngle = startAngles[index], | |
| SweepAngle = sweepAngles[index], | |
| Color = Colors[index], | |
| BackgroundColor = Color.FromArgb(backgroundAlpha, Colors[index]), | |
| Width = gaugeWidthPx, | |
| CircularBackground = CircularBackground, | |
| Clockwise = Clockwise, | |
| BackStartAngle = StartingAngleBackGauges, | |
| StartCap = StartCap, | |
| EndCap = EndCap, | |
| Mode = GaugeMode, | |
| Font = Font, | |
| FontSizeFraction = FontSizeFraction, | |
| Label = Levels[index].ToString(LevelTextFormat), | |
| LabelPositionFraction = LabelPositionFraction, | |
| ShowLabels = ShowLevels, | |
| }; |
SweepAngle = sweepAngles[index] <= 0.01 ? 0 : sweepAngles[index],or make the checking when calling DrawArc inside the RenderGaugeForeground function (it might be wiser to do the same inside RenderBackground):
gfx.DrawArc(
pen,
(center.X - radius),
(center.Y - radius),
(radius * 2),
(radius * 2),
(float)StartAngle,
SweepAngle <= 0.01 ? 0 : (float)SweepAngle);These suggestions are GDI+ dependant, meaning that they might not be needed whenever ScottPlot is ported to other graphics library.
System Details
- ScottPlot Version: 4.1.27
- Operating System: Windows 11
- Application Type: WinForms
- .NET Version: .NET 6.0
