changeset 2103:2417bc294e30

Mac: Make sure DWApp is initialized before using it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 15 Jun 2020 22:05:55 +0000
parents 9a5dbda8f2ab
children 6e55c6f8d816
files mac/dw.m
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Sat Jun 13 18:23:04 2020 +0000
+++ b/mac/dw.m	Mon Jun 15 22:05:55 2020 +0000
@@ -827,7 +827,7 @@
 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); }
 @end
 
-NSApplication *DWApp;
+NSApplication *DWApp = nil;
 NSMenu *DWMainMenu;
 NSFont *DWDefaultFont;
 DWTimerHandler *DWHandler;
@@ -12039,6 +12039,17 @@
     [oldfont release];
 }
 
+/* If DWApp is uninitialized, initialize it */
+void _dw_app_init(void)
+{
+    if(!DWApp)
+    {
+        DWApp = [NSApplication sharedApplication];
+        DWAppDel *del = [[DWAppDel alloc] init];
+        [DWApp setDelegate:del];
+    }
+}
+
 /*
  * Initializes the Dynamic Windows engine.
  * Parameters:
@@ -12101,9 +12112,7 @@
      */
     setlocale(LC_ALL, lang && strstr(lang, ".UTF-8") ? lang : "UTF-8");
     /* Create the application object */
-    DWApp = [NSApplication sharedApplication];
-    DWAppDel *del = [[DWAppDel alloc] init];
-    [DWApp setDelegate:del];
+    _dw_app_init();
     /* Create object for handling timers */
     DWHandler = [[DWTimerHandler alloc] init];
     /* If we aren't using garbage collection we need autorelease pools */
@@ -12631,6 +12640,9 @@
         {
             if(@available(macOS 10.14, *))
             {
+                /* Make sure DWApp is initialized */
+                _dw_app_init();
+                /* Get the current appearance */
                 NSAppearance *appearance = [DWApp appearance];
                 
                 if(appearance)
@@ -12685,6 +12697,8 @@
         {
             if(@available(macOS 10.14, *))
             {
+                /* Make sure DWApp is initialized */
+                _dw_app_init();
                 /* Disabled forces the non-dark aqua theme */
                 if(state == DW_FEATURE_DISABLED)
                    [DWApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];