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

IndexOutOfRangeException when having more the one floating window #291

Closed
ghost opened this Issue Jun 3, 2015 · 2 comments

Comments

Projects
None yet
3 participants
@ghost

ghost commented Jun 3, 2015

the exception happens with the following scenario:
having docked document and one or more floating window, it causes the dispose process of my app to crush.

Here are links to the problem in the code:
1)https://github.com/dockpanelsuite/dockpanelsuite/blob/master/WinFormsUI/Docking/DockPaneCollection.cs#L34
2)https://github.com/dockpanelsuite/dockpanelsuite/blob/master/WinFormsUI/Docking/FloatWindowCollection.cs#L28

during the dispose process, the code iterates over its collection and invoking the Close method, which in the described scenario invokes the following code :
https://github.com/dockpanelsuite/dockpanelsuite/blob/master/WinFormsUI/Docking/DockPaneCollection.cs#L41

the problem causes the collection to be changed within the Close method twice, while the i (index) still holding first value. which will causes IndexOutOfRangeException to be thrown.

suggested solution (only for DockPaneCollection, it supposed to be the same solution for FloatWindowCollection):
internal void Dispose()
{
List collection = new List(Items);
foreach (var dockPane in collection)
{
dockPane.Close();
}
collection.Clear();
}

the internal Items collection, should be copied to an independent collection, which will iterate over the Items collection, those allowing the internal collection to be changed. at the end process just release the independent collection references to the DockPane items.

@roken

This comment has been minimized.

Show comment
Hide comment
@roken

roken Jun 12, 2015

Member

Could you provide a copy of the exception with stack trace to better illustrate the issue?

Member

roken commented Jun 12, 2015

Could you provide a copy of the exception with stack trace to better illustrate the issue?

@nakrul79

This comment has been minimized.

Show comment
Hide comment
@nakrul79

nakrul79 Jul 17, 2015

Had the same problem. It resides in DockPaneCollection.cs. I fixed it changing the Dispose method. Closing seems to remove sometimes more than one item from the collection. Hope this helps.

    internal void Dispose()
    {
        for (int i=Count - 1; i>=0; i--)
        {
            if (i >= Count) { continue; }

            this[i].Close();
        }
    }

nakrul79 commented Jul 17, 2015

Had the same problem. It resides in DockPaneCollection.cs. I fixed it changing the Dispose method. Closing seems to remove sometimes more than one item from the collection. Hope this helps.

    internal void Dispose()
    {
        for (int i=Count - 1; i>=0; i--)
        {
            if (i >= Count) { continue; }

            this[i].Close();
        }
    }

@lextm lextm added ready in progress and removed ready labels Jul 5, 2016

@lextm lextm added this to the 2.11 milestone Jul 6, 2016

@lextm lextm closed this in fa25fa5 Jul 9, 2016

@lextm lextm removed the in progress label Jul 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment