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

@ -15,6 +15,7 @@
#include "common/graphic-helpers.h"
#include "common/list.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
#include "config/rcxml.h"
#include "input/keyboard.h"
#include "labwc.h"
@ -163,7 +164,7 @@ _osd_update(struct server *server)
cairo_destroy(cairo);
if (!output->workspace_osd) {
output->workspace_osd = wlr_scene_buffer_create(
output->workspace_osd = lab_wlr_scene_buffer_create(
&server->scene->tree, NULL);
}
/* Position the whole thing */
@ -234,13 +235,13 @@ add_workspace(struct server *server, const char *name)
struct workspace *workspace = znew(*workspace);
workspace->server = server;
workspace->name = xstrdup(name);
workspace->tree = wlr_scene_tree_create(server->workspace_tree);
workspace->tree = lab_wlr_scene_tree_create(server->workspace_tree);
workspace->view_trees[VIEW_LAYER_ALWAYS_ON_BOTTOM] =
wlr_scene_tree_create(workspace->tree);
lab_wlr_scene_tree_create(workspace->tree);
workspace->view_trees[VIEW_LAYER_NORMAL] =
wlr_scene_tree_create(workspace->tree);
lab_wlr_scene_tree_create(workspace->tree);
workspace->view_trees[VIEW_LAYER_ALWAYS_ON_TOP] =
wlr_scene_tree_create(workspace->tree);
lab_wlr_scene_tree_create(workspace->tree);
wl_list_append(&server->workspaces.all, &workspace->link);
wlr_scene_node_set_enabled(&workspace->tree->node, false);