Skip to content

Add checks to avoid OutOfMemoryException in DrawArc#1492

Merged
swharden merged 5 commits intoScottPlot:masterfrom
arthurits:RadialGaugePlot—OutOfMemoryException
Dec 26, 2021

Hidden character warning

The head ref may contain hidden characters: "RadialGaugePlot\u2014OutOfMemoryException"
Merged

Add checks to avoid OutOfMemoryException in DrawArc#1492
swharden merged 5 commits intoScottPlot:masterfrom
arthurits:RadialGaugePlot—OutOfMemoryException

Conversation

@arthurits
Copy link
Contributor

Purpose:

// This check is specific to System.Drawing since DrawArc throws an OutOfMemoryException when the sweepAngle is very small.
            if (BackEndAngle <= 0.01)
                BackEndAngle = 0;

public void RenderGaugeForeground(Graphics gfx, PointF center, float radius)

// This check is specific to System.Drawing since DrawArc throws an OutOfMemoryException when the sweepAngle is very small.
            if (SweepAngle <= 0.01)
                SweepAngle = 0;
  • A private setter was also added to BackEndAngle property
public double BackEndAngle
        {
            get
            {
                double maxBackAngle = CircularBackground ? 360 : MaximumSizeAngle;
                if (!Clockwise) maxBackAngle = -maxBackAngle;
                return maxBackAngle;
            }
            private set { BackEndAngle = value; } // Added for the sweepAngle check in DrawArc due to System.Drawing throwing an OutOfMemoryException.
        }

@arthurits
Copy link
Contributor Author

Maybe this would better discussed in another PR, but I've found that the property name BackEndAngle could be modified into BackAngleSweep, which would be more descriptive.

public double BackEndAngle

@swharden
Copy link
Member

Maybe this would better discussed in another PR, but I've found that the property name BackEndAngle could be modified into BackAngleSweep, which would be more descriptive.

This is technically a breaking change, but a small one and on a relatively new plot type so I'm fine with it. It can be included in this PR too. It's up to you whether you want to keep the old property name too marked Obsolete (I'm fine either way).

Perhaps the XML docs for this property could be more descriptive though, noting what it does and when to use it rather than just reiterating how it works.

Thanks!

@swharden
Copy link
Member

Also let me know when you're done with this PR so I don't merge it too early 👍

@arthurits
Copy link
Contributor Author

This is technically a breaking change, but a small one and on a relatively new plot type so I'm fine with it. It can be included in this PR too. It's up to you whether you want to keep the old property name too marked Obsolete (I'm fine either way).

I believe that BackEndAngle (now renamed to BackAngleSweep) is only used internally inside RadialGauge.cs to just retrieve the angular size of the gauge background when calling gfx.DrawArc. Although the property access is public, in fact it's used as private one. That's why I decided against keeping and marking the old property as Obsolete, but I'm completely fine if you think otherwise.

I also updated the XML comments. Feel free to adapt them to your preferences, and merge the PR if everything is OK.

@swharden swharden enabled auto-merge December 26, 2021 22:31
@swharden swharden merged commit 775968e into ScottPlot:master Dec 26, 2021
@arthurits arthurits deleted the RadialGaugePlot—OutOfMemoryException branch March 7, 2022 15:53
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.

RadialGaugePlot: System.Drawing throws OutOfMemoryException when drawing small arcs

2 participants