Skip to content

Commit

Permalink
fix(quickmenu): Fix crash with QuickMenu having disposed icon
Browse files Browse the repository at this point in the history
Clone the icon and use own dispose pattern to clean it up.

Fixes SOUNDSWITCH-20Q
Fixes SOUNDSWITCH-20N
  • Loading branch information
Belphemur committed Apr 9, 2024
1 parent 60c5009 commit 6a79ec9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions SoundSwitch.UI.Menu/Component/IconMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DataContainer : INotifyPropertyChanged, IDisposable
private bool _selected;
private Image? _image;
private string _label;
private Icon _icon;
private Icon? _icon;

public bool Selected
{
Expand Down Expand Up @@ -57,20 +57,22 @@ public string Label

private Icon Icon
{
get => _icon;
get => _icon!;
set
{
if (value == _icon)
{
return;
}

_icon = value;
var oldIcon = _icon;
_icon = (Icon)value.Clone();
OnPropertyChanged();
var oldImage = _image;
_image = null;
OnPropertyChanged(nameof(Image));
oldImage?.Dispose();
oldIcon?.Dispose();
}
}

Expand Down Expand Up @@ -116,6 +118,8 @@ public void Dispose()
{
_image?.Dispose();
_image = null;
_icon?.Dispose();
_icon = null;
GC.SuppressFinalize(this);
}
}
Expand Down

0 comments on commit 6a79ec9

Please sign in to comment.