win32: Abort on error
authorBenjamin Otte <otte@redhat.com>
Mon, 17 Apr 2023 02:16:50 +0000 (04:16 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 26 Apr 2023 19:03:34 +0000 (21:03 +0200)
Returning NULL from a function that must not return NULL is not a good
idea.

gdk/win32/gdksurface-win32.c

index c9970ec359f755ef51ceb39799a8618a966e7906..d18079d45baefad31c8432506c4c568e67eb5324 100644 (file)
@@ -448,7 +448,6 @@ gdk_win32_display_create_surface (GdkDisplay     *display,
                                   GdkSurfaceType  surface_type,
                                   GdkSurface     *parent)
 {
-  HWND hwndNew;
   HANDLE owner;
   ATOM klass = 0;
   DWORD dwStyle = 0, dwExStyle;
@@ -530,19 +529,23 @@ gdk_win32_display_create_surface (GdkDisplay     *display,
 
   wtitle = g_utf8_to_utf16 (title, -1, NULL, NULL, NULL);
 
-  hwndNew = CreateWindowExW (dwExStyle,
-                            MAKEINTRESOURCEW (klass),
-                            wtitle,
-                            dwStyle,
-                            CW_USEDEFAULT, CW_USEDEFAULT,
-                            CW_USEDEFAULT, CW_USEDEFAULT,
-                            owner,
-                            NULL,
-                            _gdk_dll_hinstance,
-                            surface);
-  impl->handle = hwndNew;
-
-  GetWindowRect (hwndNew, &rect);
+  impl->handle = CreateWindowExW (dwExStyle,
+                                  MAKEINTRESOURCEW (klass),
+                                  wtitle,
+                                  dwStyle,
+                                  CW_USEDEFAULT, CW_USEDEFAULT,
+                                  CW_USEDEFAULT, CW_USEDEFAULT,
+                                  owner,
+                                  NULL,
+                                  _gdk_dll_hinstance,
+                                  surface);
+  if (impl->handle == NULL)
+    {
+      WIN32_API_FAILED ("CreateWindowExW");
+      g_error ("Fatal error: CreateWindowExW failed.");
+    }
+
+  GetWindowRect (impl->handle, &rect);
   impl->initial_x = rect.left;
   impl->initial_y = rect.top;
 
@@ -559,13 +562,6 @@ gdk_win32_display_create_surface (GdkDisplay     *display,
 
   g_free (wtitle);
 
-  if (impl->handle == NULL)
-    {
-      WIN32_API_FAILED ("CreateWindowExW");
-      g_object_unref (impl);
-      return NULL;
-    }
-
   gdk_surface_set_egl_native_window (surface, (void *) impl->handle);
 
   if (surface_type != GDK_SURFACE_DRAG)