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

"System.ObjectDisposedException: Cannot access a disposed object." error on closing form #2618

Closed
DasSkelett opened this issue Dec 20, 2018 · 5 comments · Fixed by #2619
Closed
Labels
Bug Something is not working as intended GUI Issues affecting the interactive GUI Linux Issues specific for Linux Mono Issues specific for Mono

Comments

@DasSkelett
Copy link
Member

DasSkelett commented Dec 20, 2018

Background

CKAN Version:
current master branch - 1.25.5
-> Bug introduced with #2610 (Yep, that's mine.)
Bug introduced with #2556.

Operating System:
(K)ubuntu 18.04.1 - mono 5.16.0.220

Problem

What steps did you take in CKAN?
Closed the form in the mod list.

What happened?
Got an error message in the console:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'CKAN.TransparentTextBox'.
  at System.Windows.Forms.Control.CreateHandle () [0x00013] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.TextBoxBase.CreateHandle () [0x00006] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.CreateGraphics () [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control.CreateGraphics()
  at System.Windows.Forms.Document.owner_VisibleChanged (System.Object sender, System.EventArgs e) [0x0000d] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x0002f] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.SetVisibleCore (System.Boolean value) [0x00176] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control.set_Visible (System.Boolean value) [0x00009] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.SplitterPanel.set_Visible (System.Boolean value) [0x00000] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SplitterPanel.set_Visible(bool)
  at System.Windows.Forms.SplitContainer.set_Panel2Collapsed (System.Boolean value) [0x00010] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SplitContainer.set_Panel2Collapsed(bool)
  at CKAN.Main.set_ActiveModInfo (CKAN.GUIMod value) [0x0000a] in /path/to/CKAN/GUI/Main.cs:1054 
  at CKAN.Main.ModList_SelectedIndexChanged (System.Object sender, System.EventArgs e) [0x00008] in /path/to/CKAN/GUI/MainModList.cs:274 
  at System.Windows.Forms.DataGridView.OnSelectionChanged (System.EventArgs e) [0x00019] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.DataGridView.SetSelectedRowCore (System.Int32 rowIndex, System.Boolean selected) [0x0006d] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at CKAN.MainModListGUI.SetSelectedRowCore (System.Int32 rowIndex, System.Boolean selected) [0x0001f] in /path/to/CKAN/GUI/MainModList.cs:502 
  at System.Windows.Forms.DataGridView.SetSelectedRowCoreInternal (System.Int32 rowIndex, System.Boolean selected) [0x00012] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.DataGridView.SetSelectedRowCoreInternal(int,bool)
  at System.Windows.Forms.DataGridViewBand.set_Selected (System.Boolean value) [0x00027] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.DataGridViewRow.set_Selected (System.Boolean value) [0x00027] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.DataGridView.ClearSelection () [0x0004e] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.DataGridView.Dispose (System.Boolean disposing) [0x00006] in <69ecb40f27a1431a99620933ba9a8b39>:0
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Control.Dispose (System.Boolean disposing) [0x00090] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Control.Dispose (System.Boolean disposing) [0x00090] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.TabControl.Dispose (System.Boolean disposing) [0x00006] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Control.Dispose (System.Boolean disposing) [0x00090] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Control.Dispose (System.Boolean disposing) [0x00090] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ContainerControl.Dispose (System.Boolean disposing) [0x00000] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Control.Dispose (System.Boolean disposing) [0x00090] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.ContainerControl.Dispose (System.Boolean disposing) [0x00000] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Form.Dispose (System.Boolean disposing) [0x00047] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at CKAN.Main.Dispose (System.Boolean disposing) [0x00022] in /path/to/CKAN/GUI/Main.Designer.cs:20 
  at System.ComponentModel.Component.Dispose () [0x00000] in :0 
  at (wrapper remoting-invoke-with-check) System.ComponentModel.Component.Dispose()
  at System.Windows.Forms.Form.WmClose (System.Windows.Forms.Message& m) [0x000b1] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message& m) [0x000de] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x0000b] in <69ecb40f27a1431a99620933ba9a8b39>:0 
  at System.Windows.Forms.NativeWindow.WndProc (System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) [0x00085] in <69ecb40f27a1431a99620933ba9a8b39>:0 

It seems that DataGridView.Dispose() clears the selection with DataGridView.ClearSelection(),
which triggers Main.ModList_SelectedIndexChanged(),
which sets Main.ActiveModInfo to null,
that collapses splitContainer1.Panel2,
which sets itself and all its controls to Visible = false, especially all TextBoxes.
But those apparently are already disposed.

So (besides that I don't know why DataGridView.Dispose() wants to clear the selection, it's gone anyway, so why bother what's selected?...) somehow my new all textboxes of the mod info tab dispose too early.

Where I am atm

I found a workaround that I check in ActiveModInfo if actuallyVisible == false, but then you have an empty ModInfo tab after startup. That could be "fixed" if we have no row selected in our mod list at startup so the mod info is hidden.
See #2619.

Thanks for your thoughts in advance.

@DasSkelett DasSkelett changed the title "System.ObjectDisposedException: Cannot access a disposed object." crash on closing form "System.ObjectDisposedException: Cannot access a disposed object." error on closing form Dec 20, 2018
@DasSkelett
Copy link
Member Author

DasSkelett commented Dec 20, 2018

In order to have no mod selected and hide the mod info at startup, I added ModList.ClearSelection() to Main.OnShown() and moved ActiveModInfo = null there too.
The comment of ActiveModInfo = null says // Disable the modinfo controls until a mod has been choosen., but that doesn't happen. If you start CKAN, there's alwas the info panel opened.
I think this was set too early, because if I move it to OnShown(), it works...

@HebaruSan
Copy link
Member

HebaruSan commented Dec 20, 2018

Is there a property in winforms that we could use to check whether something has been disposed or is being disposed? Seems like we should just skip ModList_SelectedIndexChanged in that case.

EDIT: Or I guess we could just catch and ignore ObjectDisposedException.

@HebaruSan HebaruSan added Bug Something is not working as intended GUI Issues affecting the interactive GUI Linux Issues specific for Linux Mono Issues specific for Mono labels Dec 20, 2018
@DasSkelett
Copy link
Member Author

DasSkelett commented Dec 20, 2018

Yes, that

        private void ModList_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Skip if disposed (i.e. after the form has been closed).
            if (ModInfoTabControl.IsDisposed)
            {
                return;
            }

            var module = GetSelectedModule();

            ActiveModInfo = module;
            if (module == null)
                return;

            NavSelectMod(module);
        }

works, no error any more.

Now there's only the not-working ActiveModInfo = null in Main() left (line 250).
The question is, should it work and should no mod be selected on launch and no mod info be shown as the comment says?
Else I think this can be deleted, as this has no effect.

Sorry, something went wrong.

@HebaruSan
Copy link
Member

Is that ActiveModInfo = null line related to this problem? I can think of a scenario in which it might "work", which is if there are no mods in the mod list.

Sorry, something went wrong.

@DasSkelett
Copy link
Member Author

No, not related to this problem, I just tumbled over it.
Yeah, that might be the use case.
Then I might specify this comment a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended GUI Issues affecting the interactive GUI Linux Issues specific for Linux Mono Issues specific for Mono
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants