Skip to content

Commit

Permalink
call ImageSource.Freeze to prevent exceptions in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Oct 10, 2023
1 parent 040c574 commit f938632
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions VolumeControl/ViewModels/AudioDeviceVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public AudioDeviceVM(AudioDevice audioDevice)
AudioDevice = audioDevice;

Icon = IconExtractor.TryExtractFromPath(AudioDevice.IconPath, out ImageSource icon) ? icon : null;
Icon?.Freeze(); //< prevents WPF exceptions in some cases
Sessions = new();

// attach events to add and remove audio sessions from the Sessions list
Expand Down
2 changes: 2 additions & 0 deletions VolumeControl/ViewModels/AudioSessionVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public ImageSource? Icon
var iconPath = AudioSession.AudioSessionControl.IconPath;
if (iconPath.Length > 0 && IconExtractor.TryExtractFromPath(iconPath, out ImageSource wasapiImageSource))
{
wasapiImageSource.Freeze();
return wasapiImageSource;
}

Expand All @@ -71,6 +72,7 @@ public ImageSource? Icon
{
if (proc.GetMainModulePath() is string path && IconExtractor.TryExtractFromPath(path, out ImageSource processImageSource))
{
processImageSource.Freeze();
return processImageSource;
}
}
Expand Down

0 comments on commit f938632

Please sign in to comment.