[Problem] InitializeUIValues always calls itself -> fix DriveLetterComboBoxSelectionChanged #623

Closed
opened 2026-01-29 16:19:34 +00:00 by claunia · 4 comments
Owner

Originally created by @Deterous on GitHub (Oct 10, 2023).

Originally assigned to: @mnadareski on GitHub.

Every time InitializeUIValues is called (except perhaps during init), the function calls itself.
This is a side effect of InitializeUIValues calling PopulateDrives, which in turn runs: a8e783235c/MPF.Core/UI/ViewModels/MainViewModel.cs (L621)

By creating the list of drives, the Drive Letter Combo Box changes, which triggers DriveLetterComboBoxSelectionChanged, which in turn calls InitializeUIValues again: a8e783235c/MPF.UI.Core/Windows/MainWindow.xaml.cs (L339)

This is an obvious unintended code execution, and also causes the log to mention that there are no valid drives, because DriveLetterComboBoxSelectionChanged runs InitializeUIValues without any drives. Fortunately, rescanDrives is set to false, or else this would be recursive :)

Potential solution: DriveLetterComboBoxSelectionChanged logic can somehow be improved to ensure it is only called when the user changes the combo box, not the program itself?

Originally created by @Deterous on GitHub (Oct 10, 2023). Originally assigned to: @mnadareski on GitHub. Every time `InitializeUIValues` is called (except perhaps during init), the function calls itself. This is a side effect of `InitializeUIValues` calling `PopulateDrives`, which in turn runs: https://github.com/SabreTools/MPF/blob/a8e783235c7a6d654cf431c669697ae19fc7c51f/MPF.Core/UI/ViewModels/MainViewModel.cs#L621 By creating the list of drives, the Drive Letter Combo Box changes, which triggers `DriveLetterComboBoxSelectionChanged`, which in turn calls `InitializeUIValues` again: https://github.com/SabreTools/MPF/blob/a8e783235c7a6d654cf431c669697ae19fc7c51f/MPF.UI.Core/Windows/MainWindow.xaml.cs#L339 This is an obvious unintended code execution, and also causes the log to mention that there are no valid drives, because `DriveLetterComboBoxSelectionChanged` runs `InitializeUIValues` without any drives. Fortunately, rescanDrives is set to false, or else this would be recursive :) Potential solution: `DriveLetterComboBoxSelectionChanged` logic can somehow be improved to ensure it is only called when the user changes the combo box, not the program itself?
claunia added the bug label 2026-01-29 16:19:34 +00:00
Author
Owner

@Deterous commented on GitHub (Oct 10, 2023):

Sorry for the obtuse issue, I managed to nail down where my issue was occurring and wanted to make it clear what was happening.

Here's an example of what happens when you press the 'Scan for discs' button (which calls InitializeUIValues):
image
This showcases the issue: InitializeUIValues is run without a valid drive (when called by the drive combo box), then properly completes the second time, after "Found 1 drives: D".

@Deterous commented on GitHub (Oct 10, 2023): Sorry for the obtuse issue, I managed to nail down where my issue was occurring and wanted to make it clear what was happening. Here's an example of what happens when you press the 'Scan for discs' button (which calls `InitializeUIValues`): ![image](https://github.com/SabreTools/MPF/assets/138427222/8f641db9-6e28-4ad1-bee4-35f98570dbe2) This showcases the issue: `InitializeUIValues` is run without a valid drive (when called by the drive combo box), then properly completes the second time, after "Found 1 drives: D".
Author
Owner

@mnadareski commented on GitHub (Oct 10, 2023):

I will tackle this after the next release given that it is not a blocking issue.

@mnadareski commented on GitHub (Oct 10, 2023): I will tackle this after the next release given that it is not a blocking issue.
Author
Owner

@mnadareski commented on GitHub (Oct 11, 2023):

May be handled or partially handled by 81742a4676

@mnadareski commented on GitHub (Oct 11, 2023): May be handled or partially handled by https://github.com/SabreTools/MPF/commit/81742a4676190128512896a3f6df4597704cef7f
Author
Owner

@Deterous commented on GitHub (Oct 11, 2023):

Completely fixed by 81742a4

@Deterous commented on GitHub (Oct 11, 2023): Completely fixed by 81742a4
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SabreTools/MPF#623