Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon.Points has wrong nullability attributes #10986

Closed
Ralalu opened this issue Apr 11, 2023 · 4 comments
Closed

Polygon.Points has wrong nullability attributes #10986

Ralalu opened this issue Apr 11, 2023 · 4 comments
Labels
bug by-design The behavior reported in the issue is actually correct.

Comments

@Ralalu
Copy link

Ralalu commented Apr 11, 2023

Describe the bug
Adding points to a Shape (Polygon, Polyline,...) throw NullReferenceException:

To Reproduce

            Polyline polyLine = new Polyline()
            {
                Stroke = new SolidColorBrush(Colors.Green),
                StrokeThickness = 2.0
            };

            Avalonia.Point a = new Avalonia.Point(80, 90);
            Avalonia.Point b = new Avalonia.Point(250, 250);
            Avalonia.Point c = new Avalonia.Point(240, 220);

            //NullReferenceException occurs here:
            polyLine.Points.Add(a);
            polyLine.Points.Add(b);
            polyLine.Points.Add(c);

            canvas.Children.Add(polyLine);

Expected behavior

My current workaround:
(Or do I have to do it like this?)

            Polyline polyLine = new Polyline()
            {
                Stroke = new SolidColorBrush(Colors.Green),
                StrokeThickness = 2.0
            };

            Avalonia.Point a = new Avalonia.Point(80, 90);
            Avalonia.Point b = new Avalonia.Point(250, 250);
            Avalonia.Point c = new Avalonia.Point(240, 220);

            IList<Avalonia.Point> points = new List<Avalonia.Point>();
            points.Add(a);
            points.Add(b);
            points.Add(c);

            polyLine.Points = points;

            canvas.Children.Add(polyLine);

Desktop (please complete the following information):

  • OS: Windows 11
  • Visual Studio 2022
  • Version: Avalonia 11-Pre6
@Ralalu Ralalu added the bug label Apr 11, 2023
@maxkatz6 maxkatz6 added help-wanted A contribution from the community would be most welcome. by-design The behavior reported in the issue is actually correct. labels Apr 11, 2023
@maxkatz6 maxkatz6 changed the title Shapes: e.g. Polygon.Points.Add(a) throw NullReferenceException Polygon.Points has wrong nullability attributes Apr 11, 2023
@maxkatz6
Copy link
Member

Yes, it is by design as it seems from the API. Since it's a styled property.
But it would be less confusing, if nullable attributes were set properly.
I will this issue open until somebody fixes nullable attributes on this property.

@3steve3
Copy link

3steve3 commented Apr 11, 2023

I want to add the adding in the second example is a little verbose when you can initialize a list with those points like this:

IList<Avalonia.Point> points = new List<Avalonia.Point>
{
    a,
    b,
    c
};

@lhsrebel72
Copy link
Contributor

lhsrebel72 commented Aug 8, 2023

@maxkatz6 would this be an appropriate fix for this or am I misunderstanding?
public Polygon() { SetCurrentValue(PointsProperty, new Points()); }

changed from
public Polygon() { Points = new Points(); }

which was throwing a warning saying it should use setcurrentvalue when setting it's own styled or attached properties

@maxkatz6
Copy link
Member

maxkatz6 commented Aug 8, 2023

@lhsrebel72 no, it shouldn't be changed. See #10370 (comment)

As for this issue, it was resolved before, and that code doesn't throw anymore.

@maxkatz6 maxkatz6 closed this as completed Aug 8, 2023
@timunie timunie removed the help-wanted A contribution from the community would be most welcome. label Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug by-design The behavior reported in the issue is actually correct.
Projects
None yet
Development

No branches or pull requests

5 participants