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 System.ObjectDisposedException for TransparentTextBox #2619

Merged
merged 1 commit into from
Dec 30, 2018

Conversation

DasSkelett
Copy link
Member

@DasSkelett DasSkelett commented Dec 20, 2018

With #2610 I created a new TransparentTextBox class derived from TextBox, which allows textboxes with transparent background.
For unknown reasons, they behave different to normal textboxes when you close the GUI.
The seem to get disposed too early, because DataGridView wants to clear the selection before getting disposed. This triggers multiple methods one after the other, including Main.ModList_SelectedIndexChanged(), which finally leads to hiding the mod info tab and its included controls.
But all transparent textboxes are already disposed, so it throws the

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'CKAN.TransparentTextBox'.

error.


Workaround:

Now I break the chain in Main.ModList_SelectedIndexChanged() by testing if the ModInfoTabControl is already disposed, and if so, do nothing more, so don't try to hide every control in the end.

HebaruSan currently tries to find the cause of the bug.

Fixes #2618 , more or less.

On form close, all controls are set to invisible, but TransparentTextBoxes are already disposed.
This commit blocks the method if the the tab control is already disposed.
@HebaruSan HebaruSan added Bug Something is not working as intended GUI Issues affecting the interactive GUI Pull request Linux Issues specific for Linux Mono Issues specific for Mono labels Dec 21, 2018
@HebaruSan
Copy link
Member

Trying to figure out why your class is treated differently, TextBox has a couple of attributes on it:

	[ComVisible(true)]
	[ClassInterface (ClassInterfaceType.AutoDispatch)]

https://github.com/mono/mono/blob/0d6d334bcba28f2fb4c6cd5498b48e9c85c782d8/mcs/class/System.Windows.Forms/System.Windows.Forms/TextBox.cs#L39-L40

Can you check whether adding those to TransparentTextBox has any effect (without this PR's changes)? There must be some factor that tells the runtime to work around this exception for the built in controls, and ideally we ought to use the same thing.

If not, I kind of want to take it for a spin with a custom compiled Mono to investigate, but that would probably have to be after the 25th at this point.

@DasSkelett
Copy link
Member Author

DasSkelett commented Dec 21, 2018

Looks bad for your holidays...
Adding those lines without my previous changes throws the error again.

@politas
Copy link
Member

politas commented Dec 26, 2018

Hmm, I'm getting this when I run this branch - I get the instance selector, then it throws the exception.

$ ckan gui
System.NullReferenceException: Object reference not set to an instance of an object
  at CKAN.Main._UpdateFilters () [0x00021] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Util.Invoke[T] (T obj, System.Action action) [0x0002d] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Main.UpdateFilters (CKAN.Main control) [0x00001] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Main.<.ctor>b__37_0 (CKAN.MainModList source) [0x00000] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.MainModList.set_ModFilter (CKAN.GUIModFilter value) [0x00029] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Main.Filter (CKAN.GUIModFilter filter) [0x00007] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Main.CurrentInstanceUpdated () [0x00077] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at CKAN.Main.OnLoad (System.EventArgs e) [0x00299] in <8879e6ea4bdf46bfb52dcc353054c973>:0 
  at System.Windows.Forms.Form.OnLoadInternal (System.EventArgs e) [0x00023] in <5bcdf2a3746f4353acffcd001a2c6899>:0 

@DasSkelett
Copy link
Member Author

Huh, I have no idea how my changes could affect _updateFilters() and what variable is null and not catched there, but I'm not at home until January 8th to properly investigate this error.

@HebaruSan
Copy link
Member

I'm guessing that's #2624. I can't even launch current HEAD on Mono.

@DasSkelett
Copy link
Member Author

DasSkelett commented Dec 26, 2018

I would be happy if this is the case. I can't find any way in which my change leave something Null which is later somehow accessed (even over detours) by _updateFilters(), especially as ModList_SelectedIndexChanged() only is used to handle the mod info panel.
Also my addition should only affect closing, not opening CKAN.

@HebaruSan
Copy link
Member

Wait, if this branch hasn't been rebased or merged, then that wouldn't make sense since #2617's change wouldn't be here. Never mind...

@DasSkelett
Copy link
Member Author

That's not what I was hoping for...

Sorry, something went wrong.

@DasSkelett
Copy link
Member Author

@politas On which OS do you get the error? I don't encounter it on Kubuntu nor Windows...

Sorry, something went wrong.

@politas
Copy link
Member

politas commented Dec 29, 2018

@DasSkelett ignore my report. I'm getting the same error on master Head.

@DasSkelett
Copy link
Member Author

That's an emotional rollercoaster with you guys...

Sorry, something went wrong.

@HebaruSan
Copy link
Member

Good news, @DasSkelett, it's not your fault! Changing the controls back to ordinary TextBoxes...

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Windows.Forms.TextBox'.
  at System.Windows.Forms.Control.CreateHandle () [0x00013] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.TextBoxBase.CreateHandle () [0x00006] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.CreateGraphics () [0x00008] in <a78030b9a9a543b381a52822d20656d0>: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 <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x0002f] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnParentVisibleChanged (System.EventArgs e) [0x00008] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.OnVisibleChanged (System.EventArgs e) [0x00053] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.ScrollableControl.OnVisibleChanged (System.EventArgs e) [0x0001a] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.SetVisibleCore (System.Boolean value) [0x00176] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.Control.set_Visible (System.Boolean value) [0x00009] in <a78030b9a9a543b381a52822d20656d0>:0 
  at System.Windows.Forms.SplitterPanel.set_Visible (System.Boolean value) [0x00000] in <a78030b9a9a543b381a52822d20656d0>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.SplitterPanel.set_Visible(bool)

(etc., etc.) So this is probably caused purely by #2556. With that in mind, I think the current fix makes sense.

@DasSkelett
Copy link
Member Author

Christmas is 5 days late, but I won't complain.

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 this pull request may close these issues.

"System.ObjectDisposedException: Cannot access a disposed object." error on closing form
3 participants