From b6a7541f87c5ed07634eb829af3abdb8239aca18 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 27 Sep 2022 17:05:08 +1000 Subject: GHOST: exit with an error when GHOST cannot be initialized When the GHOST back-end Blender was built with isn't supported, Blender would crash on startup without any useful information. This could happen when building X11 only, then running on Wayland. Now show a list of the GHOST back-ends that were attempted and exit with an error code instead of crashing. --- source/blender/windowmanager/intern/wm_playanim.c | 8 ++++++++ source/blender/windowmanager/intern/wm_window.c | 7 +++++++ 2 files changed, 15 insertions(+) (limited to 'source/blender') diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index bb19ba4748f..bf793ee41a0 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -1539,6 +1539,14 @@ static char *wm_main_playanim_intern(int argc, const char **argv) GHOST_SetBacktraceHandler((GHOST_TBacktraceFn)BLI_system_backtrace); g_WS.ghost_system = GHOST_CreateSystem(); + + if (UNLIKELY(g_WS.ghost_system == NULL)) { + /* GHOST will have reported the back-ends that failed to load. */ + fprintf(stderr, "GHOST: unable to initialize, exiting!\n"); + /* This will leak memory, it's preferable to crashing. */ + exit(1); + } + GHOST_AddEventConsumer(g_WS.ghost_system, consumer); playanim_window_open("Blender Animation Player", start_x, start_y, ibuf->x, ibuf->y); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 89bf2b82426..a4f92da2774 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -1546,6 +1546,13 @@ void wm_ghost_init(bContext *C) g_system = GHOST_CreateSystem(); + if (UNLIKELY(g_system == NULL)) { + /* GHOST will have reported the back-ends that failed to load. */ + fprintf(stderr, "GHOST: unable to initialize, exiting!\n"); + /* This will leak memory, it's preferable to crashing. */ + exit(1); + } + GHOST_Debug debug = {0}; if (G.debug & G_DEBUG_GHOST) { debug.flags |= GHOST_kDebugDefault; -- cgit v1.2.3