From 5cc7342606dbbd5e6932b39e6b1b5645164669bf Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Tue, 15 Aug 2017 07:56:47 +0200 Subject: Prevent alloc errors from crashing Resolves #76 --- examples/compositor/main.c | 4 ++++ examples/rotation.c | 9 +++++++++ examples/tablet.c | 5 +++++ examples/touch.c | 9 +++++++++ 4 files changed, 27 insertions(+) (limited to 'examples') diff --git a/examples/compositor/main.c b/examples/compositor/main.c index 933e27c7..9b8a041c 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -70,6 +70,10 @@ int main() { compositor_init(&compositor); state.renderer = wlr_gles2_renderer_init(compositor.backend); + if (!state.renderer) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } wl_display_init_shm(compositor.display); wl_compositor_init(compositor.display, &state.compositor, state.renderer); wl_shell_init(compositor.display, &state.shell); diff --git a/examples/rotation.c b/examples/rotation.c index e4c3f87f..fc12558f 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "shared.h" #include "cat.h" @@ -205,7 +206,15 @@ int main(int argc, char *argv[]) { compositor_init(&compositor); state.renderer = wlr_gles2_renderer_init(compositor.backend); + if (!state.renderer) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } state.cat_texture = wlr_render_texture_init(state.renderer); + if (!state.cat_texture) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888, cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); diff --git a/examples/tablet.c b/examples/tablet.c index 0651efde..17653885 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "shared.h" #include "cat.h" @@ -153,6 +154,10 @@ int main(int argc, char *argv[]) { compositor_init(&compositor); state.renderer = wlr_gles2_renderer_init(compositor.backend); + if (!state.renderer) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } compositor_run(&compositor); wlr_renderer_destroy(state.renderer); diff --git a/examples/touch.c b/examples/touch.c index 9dd2fe57..a32c76ba 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "shared.h" #include "cat.h" @@ -105,7 +106,15 @@ int main(int argc, char *argv[]) { compositor_init(&compositor); state.renderer = wlr_gles2_renderer_init(compositor.backend); + if (!state.renderer) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } state.cat_texture = wlr_render_texture_init(state.renderer); + if (!state.cat_texture) { + wlr_log(L_ERROR, "Could not start compositor, OOM"); + exit(EXIT_FAILURE); + } wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888, cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); -- cgit v1.2.3