GHOST/Wayland: prevent eternal loop in case of an error creating windows

Check & print a message if there is an error creating the window.
In both cases Blender will fail to start, it's just better to exit
quickly with a message instead of hanging.
This commit is contained in:
Campbell Barton
2024-05-02 10:21:02 +10:00
parent 2d152db090
commit f735e4e611
3 changed files with 27 additions and 8 deletions

View File

@@ -1823,16 +1823,20 @@ static const char *ghost_wl_locale_from_env_with_default()
return locale;
}
static void ghost_wl_display_report_error_from_code(const int ecode)
{
if (ELEM(ecode, EPIPE, ECONNRESET)) {
fprintf(stderr, "The Wayland connection broke. Did the Wayland compositor die?\n");
return;
}
fprintf(stderr, "The Wayland connection experienced a fatal error: %s\n", strerror(ecode));
}
static void ghost_wl_display_report_error(wl_display *display)
{
int ecode = wl_display_get_error(display);
GHOST_ASSERT(ecode, "Error not set!");
if (ELEM(ecode, EPIPE, ECONNRESET)) {
fprintf(stderr, "The Wayland connection broke. Did the Wayland compositor die?\n");
}
else {
fprintf(stderr, "The Wayland connection experienced a fatal error: %s\n", strerror(ecode));
}
ghost_wl_display_report_error_from_code(ecode);
/* NOTE(@ideasman42): The application is running,
* however an error closes all windows and most importantly:
@@ -1848,6 +1852,16 @@ static void ghost_wl_display_report_error(wl_display *display)
::exit(-1);
}
bool ghost_wl_display_report_error_if_set(wl_display *display)
{
const int ecode = wl_display_get_error(display);
if (ecode == 0) {
return false;
}
ghost_wl_display_report_error_from_code(ecode);
return true;
}
#ifdef __GNUC__
static void ghost_wayland_log_handler(const char *msg, va_list arg)
__attribute__((format(printf, 1, 0)));

View File

@@ -35,6 +35,8 @@
class GHOST_WindowWayland;
bool ghost_wl_display_report_error_if_set(wl_display *display);
bool ghost_wl_output_own(const struct wl_output *wl_output);
void ghost_wl_output_tag(struct wl_output *wl_output);
struct GWL_Output *ghost_wl_output_user_data(struct wl_output *wl_output);

View File

@@ -1773,7 +1773,9 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
/* Commit needed to so configure callback runs. */
wl_surface_commit(window_->wl.surface);
while (!decor.initial_configure_seen) {
/* Failure exits with an error, simply prevent an eternal loop. */
while (!decor.initial_configure_seen && !ghost_wl_display_report_error_if_set(display)) {
wl_display_flush(display);
wl_display_dispatch(display);
}
@@ -1932,7 +1934,8 @@ GHOST_WindowWayland::GHOST_WindowWayland(GHOST_SystemWayland *system,
}
# endif /* WITH_VULKAN_BACKEND */
while (!decor.initial_configure_seen) {
/* Failure exits with an error, simply prevent an eternal loop. */
while (!decor.initial_configure_seen && !ghost_wl_display_report_error_if_set(display)) {
wl_display_flush(display);
wl_display_dispatch(display);
}