mirror of
https://github.com/labwc/labwc.git
synced 2026-04-07 08:21:20 -04:00
tree-wide: use die_if_null() for wlr_scene alloc failures
Some checks failed
labwc.github.io / notify (push) Has been cancelled
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:
parent
c4effef0ec
commit
16c5373be5
27 changed files with 155 additions and 141 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <assert.h>
|
||||
#include <wlr/types/wlr_scene.h>
|
||||
#include "common/mem.h"
|
||||
#include "common/scene-helpers.h"
|
||||
|
||||
struct border_scene {
|
||||
struct wlr_scene_tree *tree;
|
||||
|
|
@ -26,20 +27,20 @@ lab_scene_rect_create(struct wlr_scene_tree *parent,
|
|||
rect->border_width = opts->border_width;
|
||||
rect->nr_borders = opts->nr_borders;
|
||||
rect->borders = znew_n(rect->borders[0], opts->nr_borders);
|
||||
rect->tree = wlr_scene_tree_create(parent);
|
||||
rect->tree = lab_wlr_scene_tree_create(parent);
|
||||
|
||||
if (opts->bg_color) {
|
||||
rect->fill = wlr_scene_rect_create(rect->tree, 0, 0, opts->bg_color);
|
||||
rect->fill = lab_wlr_scene_rect_create(rect->tree, 0, 0, opts->bg_color);
|
||||
}
|
||||
|
||||
for (int i = 0; i < rect->nr_borders; i++) {
|
||||
struct border_scene *border = &rect->borders[i];
|
||||
float *color = opts->border_colors[i];
|
||||
border->tree = wlr_scene_tree_create(rect->tree);
|
||||
border->top = wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->right = wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->bottom = wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->left = wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->tree = lab_wlr_scene_tree_create(rect->tree);
|
||||
border->top = lab_wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->right = lab_wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->bottom = lab_wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
border->left = lab_wlr_scene_rect_create(border->tree, 0, 0, color);
|
||||
}
|
||||
|
||||
rect->node_destroy.notify = handle_node_destroy;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue