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

@ -3,6 +3,7 @@
#include <assert.h>
#include <wlr/types/wlr_scene.h>
#include "common/macros.h"
#include "common/scene-helpers.h"
#include "labwc.h"
#include "ssd.h"
#include "ssd-internal.h"
@ -22,32 +23,32 @@ ssd_border_create(struct ssd *ssd)
int full_width = width + 2 * theme->border_width;
int corner_width = ssd_get_corner_width();
ssd->border.tree = wlr_scene_tree_create(ssd->tree);
ssd->border.tree = lab_wlr_scene_tree_create(ssd->tree);
wlr_scene_node_set_position(&ssd->border.tree->node, -theme->border_width, 0);
enum ssd_active_state active;
FOR_EACH_ACTIVE_STATE(active) {
struct ssd_border_subtree *subtree = &ssd->border.subtrees[active];
subtree->tree = wlr_scene_tree_create(ssd->border.tree);
subtree->tree = lab_wlr_scene_tree_create(ssd->border.tree);
struct wlr_scene_tree *parent = subtree->tree;
wlr_scene_node_set_enabled(&parent->node, active);
float *color = theme->window[active].border_color;
subtree->left = wlr_scene_rect_create(parent,
subtree->left = lab_wlr_scene_rect_create(parent,
theme->border_width, height, color);
wlr_scene_node_set_position(&subtree->left->node, 0, 0);
subtree->right = wlr_scene_rect_create(parent,
subtree->right = lab_wlr_scene_rect_create(parent,
theme->border_width, height, color);
wlr_scene_node_set_position(&subtree->right->node,
theme->border_width + width, 0);
subtree->bottom = wlr_scene_rect_create(parent,
subtree->bottom = lab_wlr_scene_rect_create(parent,
full_width, theme->border_width, color);
wlr_scene_node_set_position(&subtree->bottom->node,
0, height);
subtree->top = wlr_scene_rect_create(parent,
subtree->top = lab_wlr_scene_rect_create(parent,
MAX(width - 2 * corner_width, 0), theme->border_width, color);
wlr_scene_node_set_position(&subtree->top->node,
theme->border_width + corner_width,