tree-wide: use die_if_null() for wlr_scene alloc failures
Some checks failed
labwc.github.io / notify (push) Has been cancelled

wlr_scene_*_create() functions all allocate memory via calloc() and
return NULL if the allocation fails. Previously, the failures were
handled in any of 3 different ways:

 - sending a wayland protocol error
 - exiting labwc with an error
 - segfault (no NULL check at all)

Since labwc does not attempt to survive heap exhaustion in other
allocation paths (such as `znew`), it seems more consistent to use the
same die_if_null() check used in those paths to exit with an error.

For the three most common create() functions (tree, rect, buffer),
add small lab_wlr_ wrappers to common/scene-helpers.
This commit is contained in:
John Lindgren 2026-02-23 16:34:36 -05:00 committed by Johan Malm
parent c4effef0ec
commit 16c5373be5
27 changed files with 155 additions and 141 deletions

View file

@ -231,7 +231,7 @@ preview_selected_view(struct view *view)
cycle->preview_node = &view->scene_tree->node;
/* Create a dummy node at the original place of the previewed window */
struct wlr_scene_rect *dummy_rect = wlr_scene_rect_create(
struct wlr_scene_rect *dummy_rect = lab_wlr_scene_rect_create(
cycle->preview_node->parent, 0, 0, (float [4]) {0});
wlr_scene_node_place_below(&dummy_rect->node, cycle->preview_node);
wlr_scene_node_set_enabled(&dummy_rect->node, false);

View file

@ -9,6 +9,7 @@
#include "common/lab-scene-rect.h"
#include "common/list.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
#include "common/string-helpers.h"
#include "config/rcxml.h"
#include "cycle.h"
@ -108,7 +109,7 @@ cycle_osd_classic_init(struct cycle_osd_output *osd_output)
int h = workspace_name_h + nr_visible_views * switcher_theme->item_height
+ 2 * padding;
osd_output->tree = wlr_scene_tree_create(output->cycle_osd_tree);
osd_output->tree = lab_wlr_scene_tree_create(output->cycle_osd_tree);
float *text_color = theme->osd_label_text_color;
float *bg_color = theme->osd_bg_color;
@ -161,7 +162,7 @@ cycle_osd_classic_init(struct cycle_osd_output *osd_output)
float *active_bg_color = switcher_theme->item_active_bg_color;
float *active_border_color = switcher_theme->item_active_border_color;
osd_output->items_tree = wlr_scene_tree_create(osd_output->tree);
osd_output->items_tree = lab_wlr_scene_tree_create(osd_output->tree);
/* Draw text for each node */
struct view *view;
@ -169,7 +170,7 @@ cycle_osd_classic_init(struct cycle_osd_output *osd_output)
struct cycle_osd_classic_item *item = znew(*item);
wl_list_append(&osd_output->items, &item->base.link);
item->base.view = view;
item->base.tree = wlr_scene_tree_create(osd_output->items_tree);
item->base.tree = lab_wlr_scene_tree_create(osd_output->items_tree);
node_descriptor_create(&item->base.tree->node,
LAB_NODE_CYCLE_OSD_ITEM, NULL, item);
/*
@ -191,8 +192,8 @@ cycle_osd_classic_init(struct cycle_osd_output *osd_output)
int x = padding
+ switcher_theme->item_active_border_width
+ switcher_theme->item_padding_x;
item->normal_tree = wlr_scene_tree_create(item->base.tree);
item->active_tree = wlr_scene_tree_create(item->base.tree);
item->normal_tree = lab_wlr_scene_tree_create(item->base.tree);
item->active_tree = lab_wlr_scene_tree_create(item->base.tree);
wlr_scene_node_set_enabled(&item->active_tree->node, false);
/* Highlight around selected window's item */
@ -209,7 +210,7 @@ cycle_osd_classic_init(struct cycle_osd_output *osd_output)
wlr_scene_node_set_position(&highlight_rect->tree->node, padding, y);
/* hitbox for mouse clicks */
struct wlr_scene_rect *hitbox = wlr_scene_rect_create(item->base.tree,
struct wlr_scene_rect *hitbox = lab_wlr_scene_rect_create(item->base.tree,
w - 2 * padding, switcher_theme->item_height, (float[4]) {0});
wlr_scene_node_set_position(&hitbox->node, padding, y);

View file

@ -2,6 +2,7 @@
#include <assert.h>
#include <wlr/types/wlr_scene.h>
#include "common/lab-scene-rect.h"
#include "common/scene-helpers.h"
#include "labwc.h"
#include "cycle.h"
#include "output.h"
@ -23,7 +24,7 @@ cycle_osd_scroll_init(struct cycle_osd_output *osd_output, struct wlr_box bar_ar
scroll->top_row_idx = 0;
scroll->bar_area = bar_area;
scroll->delta_y = delta_y;
scroll->bar_tree = wlr_scene_tree_create(osd_output->tree);
scroll->bar_tree = lab_wlr_scene_tree_create(osd_output->tree);
wlr_scene_node_set_position(&scroll->bar_tree->node,
bar_area.x, bar_area.y);

View file

@ -10,6 +10,7 @@
#include "common/lab-scene-rect.h"
#include "common/list.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
#include "cycle.h"
#include "labwc.h"
#include "node.h"
@ -138,7 +139,7 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
struct cycle_osd_thumbnail_item *item = znew(*item);
wl_list_append(&osd_output->items, &item->base.link);
struct wlr_scene_tree *tree = wlr_scene_tree_create(parent);
struct wlr_scene_tree *tree = lab_wlr_scene_tree_create(parent);
node_descriptor_create(&tree->node, LAB_NODE_CYCLE_OSD_ITEM, NULL, item);
item->base.tree = tree;
item->base.view = view;
@ -155,14 +156,14 @@ create_item_scene(struct wlr_scene_tree *parent, struct view *view,
item->active_bg = lab_scene_rect_create(tree, &opts);
/* hitbox for mouse clicks */
wlr_scene_rect_create(tree, switcher_theme->item_width,
lab_wlr_scene_rect_create(tree, switcher_theme->item_width,
switcher_theme->item_height, (float[4]) {0});
/* thumbnail */
struct wlr_buffer *thumb_buffer = render_thumb(osd_output->output, view);
if (thumb_buffer) {
struct wlr_scene_buffer *thumb_scene_buffer =
wlr_scene_buffer_create(tree, thumb_buffer);
lab_wlr_scene_buffer_create(tree, thumb_buffer);
wlr_buffer_drop(thumb_buffer);
struct wlr_box thumb_box = box_fit_within(
thumb_buffer->width, thumb_buffer->height,
@ -239,8 +240,8 @@ cycle_osd_thumbnail_init(struct cycle_osd_output *osd_output)
&theme->osd_window_switcher_thumbnail;
int padding = theme->osd_border_width + switcher_theme->padding;
osd_output->tree = wlr_scene_tree_create(output->cycle_osd_tree);
osd_output->items_tree = wlr_scene_tree_create(osd_output->tree);
osd_output->tree = lab_wlr_scene_tree_create(output->cycle_osd_tree);
osd_output->items_tree = lab_wlr_scene_tree_create(osd_output->tree);
int nr_views = wl_list_length(&server->cycle.views);
assert(nr_views > 0);