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 red X on HideTab #2501

Merged
merged 1 commit into from
Aug 22, 2018
Merged

Conversation

HebaruSan
Copy link
Member

Problem

If you install a mod with recommendations, suggestions, or a provides dependency in GUI on Linux with a recent-ish version of Mono, you get a big red X when you accept the recommendations or provides selection prompt:

ckan

This was observed on Mono 5.14.0.177, but it works fine on Mono 5.10.1.20. Intermediate versions have not yet been tested.

Cause

As of some recent version of Mono, it's apparently no longer safe to hide the active tab of a TabControl. The control keeps the active tab index as it was, pointing to the removed tab, and then when the runtime attempts to draw the control, it tries to use that index to get the active tab, which doesn't work because it's gone:

System.ArgumentOutOfRangeException: ControlCollection does not have that many controls
Parameter name: index
Actual value was 3.
  at System.Windows.Forms.Control+ControlCollection.get_Item (System.Int32 index) [0x00027] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.TabControl.GetTab (System.Int32 index) [0x00006] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.TabControl.GetTabRect (System.Int32 index) [0x00000] in <185f5064526646d192550947861d97b1>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.TabControl.GetTabRect(int)
  at System.Windows.Forms.Theming.Default.TabControlPainter.Draw (System.Drawing.Graphics dc, System.Drawing.Rectangle area, System.Windows.Forms.TabControl tab) [0x000df] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.ThemeWin32Classic.DrawTabControl (System.Drawing.Graphics dc, System.Drawing.Rectangle area, System.Windows.Forms.TabControl tab) [0x0000a] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.TabControl.Draw (System.Drawing.Graphics dc, System.Drawing.Rectangle clip) [0x00005] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.TabControl.OnPaintInternal (System.Windows.Forms.PaintEventArgs pe) [0x00017] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message& m) [0x0006d] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x001a4] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.TabControl.WndProc (System.Windows.Forms.Message& m) [0x00057] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x0000b] in <185f5064526646d192550947861d97b1>:0 
  at System.Windows.Forms.NativeWindow.WndProc (System.IntPtr hWnd, System.Windows.Forms.Msg msg, System.IntPtr wParam, System.IntPtr lParam) [0x00085] in <185f5064526646d192550947861d97b1>:0 

(However, the actual code for TabControl hasn't changed in many years. Maybe it's a new race condition due to threading changes in the draw logic? Who knows.)

This happens in two places currently:

tabController.HideTab("ChooseRecommendedModsTabPage");

tabController.HideTab("ChooseProvidedModsTabPage");

It can also be made to happen in a third place if we move a HideTab call before a ShowTab call:

CKAN/GUI/MainChangeset.cs

Lines 108 to 109 in 37c8477

tabController.ShowTab("ManageModsTabPage");
tabController.HideTab("ChangesetTabPage");

Changes

Luckily we already have a TabController wrapper, so we can work around this cleanly.

Now TabController.HideTab calls DeselectTab if the tab it's hiding is selected (which Mono should be doing itself anyway). This makes it safe to hide tabs again.

Fixes #2499.

@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 Aug 15, 2018
@Stigmate-Fr
Copy link

Stigmate-Fr commented Aug 16, 2018

It work greats after compiling on ubuntu 18.04 ! THANK YOU !

@smythe811
Copy link

Confirmed, recompiled on Mint 19 (18.04 base) and this corrected the issue in #2499.

@politas
Copy link
Member

politas commented Aug 21, 2018

A nice clean fix, looks good to me!. I'll merge and push out a new release tonight/tomorrow.

@politas politas merged commit 621b3d3 into KSP-CKAN:master Aug 22, 2018
politas added a commit that referenced this pull request Aug 22, 2018
@HebaruSan HebaruSan deleted the fix/red-x-on-hidetab branch August 22, 2018 14:47
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.

4 participants