mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
examples: assert on memory allocation
Also checks for NULL output in the `X_from_device` functions
This commit is contained in:
parent
ebef710746
commit
7cb206deb4
11 changed files with 39 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <assert.h>
|
||||
#include <drm_fourcc.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -103,6 +104,7 @@ static void touch_down_notify(struct wl_listener *listener, void *data) {
|
|||
struct touch_state *tstate = wl_container_of(listener, tstate, down);
|
||||
struct sample_state *sample = tstate->sample;
|
||||
struct touch_point *point = calloc(1, sizeof(*point));
|
||||
assert(point);
|
||||
point->touch_id = event->touch_id;
|
||||
point->x = event->x;
|
||||
point->y = event->y;
|
||||
|
|
@ -174,6 +176,7 @@ static void new_output_notify(struct wl_listener *listener, void *data) {
|
|||
wlr_output_init_render(output, sample->allocator, sample->renderer);
|
||||
|
||||
struct sample_output *sample_output = calloc(1, sizeof(*sample_output));
|
||||
assert(sample_output);
|
||||
sample_output->output = output;
|
||||
sample_output->sample = sample;
|
||||
wl_signal_add(&output->events.frame, &sample_output->frame);
|
||||
|
|
@ -221,6 +224,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
|||
switch (device->type) {
|
||||
case WLR_INPUT_DEVICE_KEYBOARD:;
|
||||
struct sample_keyboard *keyboard = calloc(1, sizeof(*keyboard));
|
||||
assert(keyboard);
|
||||
keyboard->wlr_keyboard = wlr_keyboard_from_input_device(device);
|
||||
keyboard->sample = sample;
|
||||
wl_signal_add(&device->events.destroy, &keyboard->destroy);
|
||||
|
|
@ -244,6 +248,7 @@ static void new_input_notify(struct wl_listener *listener, void *data) {
|
|||
break;
|
||||
case WLR_INPUT_DEVICE_TOUCH:;
|
||||
struct touch_state *tstate = calloc(1, sizeof(*tstate));
|
||||
assert(tstate);
|
||||
tstate->wlr_touch = wlr_touch_from_input_device(device);
|
||||
tstate->sample = sample;
|
||||
tstate->destroy.notify = touch_destroy_notify;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue