Wayland: Abort on fatal display errors instead of looping forever

This commit is contained in:
Kovid Goyal 2019-03-22 08:53:10 +05:30
parent 971c28ce97
commit ecf2c86787
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

46
glfw/wl_window.c vendored
View File

@ -839,27 +839,45 @@ animateCursorImage(id_type timer_id, void *data) {
incrementCursorImage(_glfw.wl.pointerFocus);
}
static void
handleEvents(double timeout)
{
struct wl_display* display = _glfw.wl.display;
while (wl_display_prepare_read(display) != 0) {
wl_display_dispatch_pending(display);
}
// If an error different from EAGAIN happens, we have likely been
// disconnected from the Wayland session, try to handle that the best we
// can.
if (wl_display_flush(display) < 0 && errno != EAGAIN)
{
abortOnFatalError(int last_error) {
_glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: fatal display error: %s", strerror(last_error));
_GLFWwindow* window = _glfw.windowListHead;
while (window)
{
_glfwInputWindowCloseRequest(window);
window = window->next;
}
}
static void
handleEvents(double timeout)
{
struct wl_display* display = _glfw.wl.display;
errno = 0;
while (wl_display_prepare_read(display) != 0) {
while(1) {
errno = 0;
int num_dispatched = wl_display_dispatch_pending(display);
if (num_dispatched == 0) return;
if (num_dispatched < 0) {
if (errno == EAGAIN) continue;
int last_error = wl_display_get_error(display);
if (last_error) abortOnFatalError(last_error);
return;
}
break;
}
}
// If an error different from EAGAIN happens, we have likely been
// disconnected from the Wayland session, try to handle that the best we
// can.
errno = 0;
if (wl_display_flush(display) < 0 && errno != EAGAIN)
{
abortOnFatalError(errno);
wl_display_cancel_read(display);
return;
}