Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorVsevolod Kukol <sevoku@microsoft.com>2019-11-06 10:55:05 +0300
committermonojenkins <jo.shields+jenkins@xamarin.com>2019-11-08 17:02:57 +0300
commita8e6fd5774c2dbc0792b6abd65b9cd24a97e7f88 (patch)
tree5862d4bf32a17a4f60b4cd143a7896d5e04c11a9 /main
parent5d666f05d5acaab5ab9042cd8257b27e0ac64ab6 (diff)
[Mac] Cache observer objects generated by notification center to avoid native crashes with KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED
Diffstat (limited to 'main')
-rw-r--r--main/src/addins/MacPlatform/MacPlatform.cs17
1 files changed, 11 insertions, 6 deletions
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs
index 10e84948fb..3916678154 100644
--- a/main/src/addins/MacPlatform/MacPlatform.cs
+++ b/main/src/addins/MacPlatform/MacPlatform.cs
@@ -72,6 +72,11 @@ namespace MonoDevelop.MacIntegration
static bool initedGlobal;
bool setupFail, initedApp;
+ // hold a reference on all observer objects generated by the notification center
+ // NOTE: these objects should not be actively disposed on macOS 10.11 and later, unless removed manually
+ // not keeping a reference might cause a runtime crash when observers are added:
+ // KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED
+ List<IDisposable> notificationObservers = new List<IDisposable> ();
readonly Lazy<Dictionary<string, string>> mimemap = new Lazy<Dictionary<string, string>> (LoadMimeMap);
@@ -317,12 +322,12 @@ namespace MonoDevelop.MacIntegration
SwizzleNSApplication ();
var nc = NSNotificationCenter.DefaultCenter;
- nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
+ notificationObservers.Add (nc.AddObserver ((NSString)"AtkCocoaAccessibilityEnabled", (NSNotification) => {
LoggingService.LogInfo ($"VoiceOver on {IdeTheme.AccessibilityEnabled}");
if (!IdeTheme.AccessibilityEnabled) {
ShowVoiceOverNotice ();
}
- }, NSApplication.SharedApplication);
+ }, NSApplication.SharedApplication));
// Now that Cocoa has been initialized we can check whether the keyboard focus mode is turned on
// See System Preferences - Keyboard - Shortcuts - Full Keyboard Access
@@ -571,19 +576,19 @@ namespace MonoDevelop.MacIntegration
if (MacSystemInformation.OsVersion >= MacSystemInformation.Mojave) {
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
- NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif =>
+ notificationObservers.Add (NSApplication.SharedApplication.AddObserver ("effectiveAppearance", NSKeyValueObservingOptions.New, notif =>
Core.Runtime.RunInMainThread (() => {
IdeTheme.HighContrastThemeEnabled = GetIsHighContrastActive ();
PatchGtkTheme ();
})
- );
+ ));
} else {
IdeTheme.HighContrastThemeEnabled = false;
- NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
+ notificationObservers.Add (NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Core.Runtime.RunInMainThread (
delegate {
Styles.LoadStyle ();
PatchGtkTheme ();
- }));
+ })));
}
if (MacSystemInformation.OsVersion < MacSystemInformation.Mojave) { // the shared color panel has full automatic theme support on Mojave