KristofferStrube / Blazor.SVGEditor

A basic SVG editor written in Blazor.
https://kristofferstrube.github.io/Blazor.SVGEditor/
MIT License
306 stars 51 forks source link

Bugix : `Elements.IndexOf(element)` value should be checked to avoid crashes #4

Closed pcarret closed 2 years ago

pcarret commented 2 years ago

When removing elements and adding new one then removing, it can crash

in SVG.razor.cs

        protected override void OnInitialized()
        {

            ElementSubject
                .Buffer(TimeSpan.FromMilliseconds(33))
                .Where(updates => updates.Count > 0)
                .Subscribe(updates =>
                {
                    updates
                        .Distinct()
                        .ToList()
                        .ForEach(element =>
                        {
                            ElementsAsHtml[Elements.IndexOf(element)] = element.ToHtml();
                        });
                    UpdateInput();
                });
        }

Don't you think Elements.IndexOf(element) value should be checked to secure the code and avoid crashes ? image

KristofferStrube commented 2 years ago

I think the solution to this problem is to make Elements private and add accessors that ensure ElementsAsHtml is updated accordingly when Elements is changed.

I will look into this.

KristofferStrube commented 2 years ago

I have separated the responsibility of the generated Html to each ISVGElement so that SVG doesn't have to handle that. So some nice Separation of Concerns.