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

fix ResizableArray #51

Merged
merged 1 commit into from
Aug 13, 2024
Merged

fix ResizableArray #51

merged 1 commit into from
Aug 13, 2024

Conversation

prozolic
Copy link
Contributor

IndexOutOfRangeException was thrown in some cases when executing ObservableHashSet.AddRange.

static IEnumerable<int> Range(int count)
{
    foreach (var i in Enumerable.Range(0, count))
    {
        yield return i;
    }
}

var set = new ObservableHashSet<int>();
set.AddRange(Range(20));

The reason is that when ResizableArray<T>.EnsureCapacity is executed, the capacity of the new array equals the capacity of the old array.
Therefore, I modified it to create a new array with twice the capacity of the old one.

@neuecc
Copy link
Member

neuecc commented Aug 13, 2024

Thank you!
This was a terrible bug.

@neuecc neuecc merged commit d349335 into Cysharp:master Aug 13, 2024
1 check passed
@prozolic prozolic deleted the pullreq branch August 13, 2024 13:42
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.

2 participants