Skip to content

Commit ab8c0ee

Browse files
authored
fix(MMNotificationClient): Fix possible crash when closing the app
Fixes #1201
1 parent cb3d63f commit ab8c0ee

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

SoundSwitch/Framework/NotificationManager/MMNotificationClient.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ public void OnPropertyValueChanged(object sender, DevicePropertyChangedEventArgs
174174

175175
public void Dispose()
176176
{
177-
_notificationClient.DeviceAdded -= OnDeviceAdded;
178-
_notificationClient.DeviceRemoved -= OnDeviceRemoved;
179-
_notificationClient.DevicePropertyChanged -= OnPropertyValueChanged;
180-
_notificationClient.DeviceStateChanged -= OnDeviceStateChanged;
181-
_notificationClient.DefaultDeviceChanged -= OnDefaultDeviceChanged;
177+
//If register wasn't called, _notificationClient can be null
178+
_notificationClient?.DeviceAdded -= OnDeviceAdded;
179+
_notificationClient?.DeviceRemoved -= OnDeviceRemoved;
180+
_notificationClient?.DevicePropertyChanged -= OnPropertyValueChanged;
181+
_notificationClient?.DeviceStateChanged -= OnDeviceStateChanged;
182+
_notificationClient?.DefaultDeviceChanged -= OnDefaultDeviceChanged;
182183
_notificationClient = null;
183184
_mmDeviceEnumerator = null;
184185
}
185186
}
186-
}
187+
}

0 commit comments

Comments
 (0)