[client] wayland: clean up failed window initialization

This commit is contained in:
Geoffrey McRae
2026-08-12 02:56:05 +10:00
parent 8187177c7f
commit 6ddf1d62cd

View File

@@ -167,7 +167,7 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
if (!wlWm.frameEvent) if (!wlWm.frameEvent)
{ {
DEBUG_ERROR("Failed to initialize event for waitFrame"); DEBUG_ERROR("Failed to initialize event for waitFrame");
return false; goto fail;
} }
waylandSignalFrame(LG_DS_WAIT_FRAME_INTERRUPTED); waylandSignalFrame(LG_DS_WAIT_FRAME_INTERRUPTED);
@@ -176,7 +176,7 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
if (wlWm.resizeEventFd < 0) if (wlWm.resizeEventFd < 0)
{ {
DEBUG_ERROR("Failed to create the resize eventfd: %s", strerror(errno)); DEBUG_ERROR("Failed to create the resize eventfd: %s", strerror(errno));
return false; goto fail;
} }
if (!waylandPollRegister(wlWm.resizeEventFd, resizePollCallback, NULL, if (!waylandPollRegister(wlWm.resizeEventFd, resizePollCallback, NULL,
@@ -185,22 +185,20 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
DEBUG_ERROR("Failed to register the resize eventfd"); DEBUG_ERROR("Failed to register the resize eventfd");
close(wlWm.resizeEventFd); close(wlWm.resizeEventFd);
wlWm.resizeEventFd = -1; wlWm.resizeEventFd = -1;
return false; goto fail;
} }
if (!wlWm.compositor) if (!wlWm.compositor)
{ {
DEBUG_ERROR("Compositor missing wl_compositor (version 3+), will not proceed"); DEBUG_ERROR("Compositor missing wl_compositor (version 3+), will not proceed");
resizeEventFdFree(); goto fail;
return false;
} }
wlWm.surface = wl_compositor_create_surface(wlWm.compositor); wlWm.surface = wl_compositor_create_surface(wlWm.compositor);
if (!wlWm.surface) if (!wlWm.surface)
{ {
DEBUG_ERROR("Failed to create wl_surface"); DEBUG_ERROR("Failed to create wl_surface");
resizeEventFdFree(); goto fail;
return false;
} }
wl_surface_add_listener(wlWm.surface, &wlSurfaceListener, NULL); wl_surface_add_listener(wlWm.surface, &wlSurfaceListener, NULL);
@@ -222,10 +220,7 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
if (!wlWm.desktop->shellInit(wlWm.display, wlWm.surface, if (!wlWm.desktop->shellInit(wlWm.display, wlWm.surface,
title, appId, fullscreen, maximize, borderless, resizable)) title, appId, fullscreen, maximize, borderless, resizable))
{ goto fail;
resizeEventFdFree();
return false;
}
INTERLOCKED_SECTION(wlWm.surfaceLock, INTERLOCKED_SECTION(wlWm.surfaceLock,
{ {
@@ -239,12 +234,15 @@ bool waylandWindowInit(const char * title, const char * appId, bool fullscreen,
if (wl_display_roundtrip(wlWm.display) < 0) if (wl_display_roundtrip(wlWm.display) < 0)
{ {
DEBUG_ERROR("Failed waiting for the initial Wayland configure"); DEBUG_ERROR("Failed waiting for the initial Wayland configure");
resizeEventFdFree(); goto fail;
return false;
} }
} }
return true; return true;
fail:
waylandWindowFree();
return false;
} }
void waylandWindowFree(void) void waylandWindowFree(void)
@@ -260,11 +258,28 @@ void waylandWindowFree(void)
} }
if (wlWm.fractionalScaleInterface) if (wlWm.fractionalScaleInterface)
{
wp_fractional_scale_v1_destroy(wlWm.fractionalScaleInterface); wp_fractional_scale_v1_destroy(wlWm.fractionalScaleInterface);
wlWm.fractionalScaleInterface = NULL;
}
if (wlWm.contentType) if (wlWm.contentType)
{
wp_content_type_v1_destroy(wlWm.contentType); wp_content_type_v1_destroy(wlWm.contentType);
wl_surface_destroy(wlWm.surface); wlWm.contentType = NULL;
lgFreeEvent(wlWm.frameEvent); }
if (wlWm.surface)
{
wl_surface_destroy(wlWm.surface);
wlWm.surface = NULL;
}
if (wlWm.frameEvent)
{
lgFreeEvent(wlWm.frameEvent);
wlWm.frameEvent = NULL;
}
} }
void waylandSetWindowSize(int x, int y) void waylandSetWindowSize(int x, int y)