diff --git a/gtk/gtkcssnode.c b/gtk/gtkcssnode.c
index b363d77..56291cf 100644
--- a/gtk/gtkcssnode.c
+++ b/gtk/gtkcssnode.c
@@ -658,9 +658,13 @@ gtk_css_node_class_init (GtkCssNodeClass *klass)
 static void
 gtk_css_node_init (GtkCssNode *cssnode)
 {
+  GtkCssStyle *style;
+
   cssnode->decl = gtk_css_node_declaration_new ();
 
-  cssnode->style = g_object_ref (gtk_css_static_style_get_default ());
+  style = gtk_css_static_style_get_default ();
+  if (style)
+    cssnode->style = g_object_ref (style);
 
   cssnode->visible = TRUE;
 }
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index f8ce970..59bf11e 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -155,11 +155,14 @@ gtk_css_static_style_get_default (void)
       GtkSettings *settings;
 
       settings = gtk_settings_get_default ();
-      default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (settings),
-                                                        NULL,
-                                                        NULL);
-      g_object_set_data_full (G_OBJECT (settings), "gtk-default-style",
-                              default_style, clear_default_style);
+      if (settings)
+        {
+          default_style = gtk_css_static_style_new_compute (GTK_STYLE_PROVIDER_PRIVATE (settings),
+                                                            NULL,
+                                                            NULL);
+          g_object_set_data_full (G_OBJECT (settings), "gtk-default-style",
+                                  default_style, clear_default_style);
+        }
     }
 
   return default_style;
diff --git a/gtk/gtkcsswidgetnode.c b/gtk/gtkcsswidgetnode.c
index a112d7c..5751efd 100644
--- a/gtk/gtkcsswidgetnode.c
+++ b/gtk/gtkcsswidgetnode.c
@@ -241,7 +241,11 @@ gtk_css_widget_node_class_init (GtkCssWidgetNodeClass *klass)
 static void
 gtk_css_widget_node_init (GtkCssWidgetNode *node)
 {
-  node->last_updated_style = g_object_ref (gtk_css_static_style_get_default ());
+  GtkCssStyle *style;
+
+  style = gtk_css_static_style_get_default ();
+  if (style)
+    node->last_updated_style = g_object_ref (style);
 }
 
 GtkCssNode *
