sledge icon indicating copy to clipboard operation
sledge copied to clipboard

Sledge stuck in infinite loop when multiple tabs are open

Open SamVanheer opened this issue 4 years ago • 1 comments

When multiple tabs are open Sledge will get stuck in an infinite loop because it continually raises Document:Activated events in response to tab change events. An event handler for Document:Activated sets the tab index which raises the tab change event.

The documentation for SelectedIndex and SelectedIndexChanged say nothing about raising events if the value is the same, and the source code for the Core port (https://github.com/dotnet/winforms/blob/bced3b69dfb164230f300877a595afc9a000d1a6/src/System.Windows.Forms/src/System/Windows/Forms/TabControl.cs) indicates that it shouldn't, but it is calling into native code for a portion of the logic.

I suggest adding a sanity check to the event handler to ignore tab change events if the index hasn't actually changed to stop the infinite loop. Alternatively, don't change the tab index if the value is identical (this should match what WinForms is doing internally though).

Note that this only appears to be happening when Sledge is opened with multiple tabs to restore. It didn't happen when i initially opened the maps.

SamVanheer avatar Jul 18 '19 14:07 SamVanheer

It's possible that what i experienced was actually caused by the Oy event system delaying the response so this happens:

  1. First map is loaded and made current, event is pushed
  2. Second map is loaded and made current, event is pushed
  3. Third map is loaded and made current, event is pushed
  4. First event is handled and makes first map current, event is pushed
  5. Second event is handled and makes second map current, event is pushed
  6. Third event is handled and makes third map current, event is pushed
  7. Goto 4

SamVanheer avatar Jul 20 '19 16:07 SamVanheer