sway_text_node: fix cairo_create without a backing surface

This fixes sway not being able to draw text on text nodes.

cairo_create(NULL) returns a nil object in an error state rather than
NULL, causing the null check to never trigger and passing a broken cairo
context to get_text_size, which was fine until 40e1dcd29f adding error
handling to it and causing pango_cairo_update_layout to fail with a NULL
pointer.
This commit is contained in:
llyyr 2026-03-21 12:01:18 +05:30 committed by Simon Ser
parent 8378c560c1
commit e4870d84a2

View file

@ -198,7 +198,10 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
static void text_calc_size(struct text_buffer *buffer) {
struct sway_text_node *props = &buffer->props;
cairo_t *c = cairo_create(NULL);
cairo_surface_t *recorder = cairo_recording_surface_create(
CAIRO_CONTENT_COLOR_ALPHA, NULL);
cairo_t *c = cairo_create(recorder);
cairo_surface_destroy(recorder);
if (!c) {
sway_log(SWAY_ERROR, "cairo_t allocation failed");
return;