fix(display): crash on display item after custom resolution removal (#77)

This commit is contained in:
Youduo Liu
2025-02-01 16:51:48 +08:00
parent b6ee794f0f
commit 58f08a9224
+27 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
@@ -115,6 +116,24 @@ namespace ParsecVDisplay.Components
});
}
// Handle removed custom resolution
if (SelectedResolution == null)
{
SelectedResolution = new Display.ModeSet
{
Width = Display.CurrentMode.Width,
Height = Display.CurrentMode.Height,
RefreshRates = new List<int> { Display.CurrentMode.Hz }
};
xResolution.Items.Add(new MenuItem
{
IsCheckable = false,
IsChecked = true,
Header = $"{SelectedResolution.Width} × {SelectedResolution.Height} [UnSupported]",
});
}
UpdateRefreshRates();
int oridentationIndex = (int)Display.CurrentOrientation;
@@ -124,12 +143,18 @@ namespace ParsecVDisplay.Components
private void ChangeResolution(object sender, RoutedEventArgs e)
{
if (Active && e.OriginalSource != null)
if (Active && e.OriginalSource != null && e.OriginalSource is MenuItem)
{
var srcItem = e.OriginalSource as MenuItem;
if (srcItem.Header.ToString().Contains("[UnSupported]"))
{
return;
}
for (int i = 0; i < xResolution.Items.Count; i++)
{
var item = xResolution.Items[i] as MenuItem;
if (item == e.OriginalSource)
if (item == srcItem)
{
item.IsChecked = true;
SelectedResolution = Display.SupportedResolutions[i];