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

Open
opened 2026-01-29 16:19:31 +00:00 by claunia · 0 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:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SabreTools/MPF#620