From 60c4e64b9b337ad8c4014ac0b859ffb278a36774 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 8 Oct 2020 16:17:00 +0200 Subject: [PATCH] Add xcb error assertions instead of segfaulting These things should not fail (and I've never seen one of these thing error out with yabridge), but in the case they do an assertion is at least a lot trace down than a segfault. --- src/wine-host/editor.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/wine-host/editor.cpp b/src/wine-host/editor.cpp index 9bd7044a..a0149b78 100644 --- a/src/wine-host/editor.cpp +++ b/src/wine-host/editor.cpp @@ -221,6 +221,8 @@ void Editor::handle_x11_events() const { } void Editor::fix_local_coordinates() const { + xcb_generic_error_t* error; + // We're purposely not using XEmbed. This has the consequence that wine // still thinks that any X and Y coordinates are relative to the x11 window // root instead of the parent window provided by the DAW, causing all sorts @@ -235,7 +237,8 @@ void Editor::fix_local_coordinates() const { const auto query_cookie = xcb_query_tree(x11_connection.get(), parent_window); xcb_window_t root = - xcb_query_tree_reply(x11_connection.get(), query_cookie, nullptr)->root; + xcb_query_tree_reply(x11_connection.get(), query_cookie, &error)->root; + assert(!error); // We can't directly use the `event.x` and `event.y` coordinates because the // parent window may also be embedded inside another window. @@ -243,7 +246,8 @@ void Editor::fix_local_coordinates() const { x11_connection.get(), parent_window, root, 0, 0); const xcb_translate_coordinates_reply_t* translated_coordinates = xcb_translate_coordinates_reply(x11_connection.get(), translate_cookie, - nullptr); + &error); + assert(!error); xcb_configure_notify_event_t translated_event{}; translated_event.response_type = XCB_CONFIGURE_NOTIFY; @@ -348,19 +352,24 @@ LRESULT CALLBACK window_proc(HWND handle, xcb_window_t find_topmost_window(xcb_connection_t& x11_connection, xcb_window_t starting_at) { + xcb_generic_error_t* error; + xcb_window_t current_window = starting_at; xcb_query_tree_cookie_t query_cookie = xcb_query_tree(&x11_connection, starting_at); xcb_query_tree_reply_t* query_reply = - xcb_query_tree_reply(&x11_connection, query_cookie, nullptr); + xcb_query_tree_reply(&x11_connection, query_cookie, &error); + assert(!error); + xcb_window_t root = query_reply->root; while (query_reply->parent != root) { current_window = query_reply->parent; query_cookie = xcb_query_tree(&x11_connection, current_window); query_reply = - xcb_query_tree_reply(&x11_connection, query_cookie, nullptr); + xcb_query_tree_reply(&x11_connection, query_cookie, &error); + assert(!error); } return current_window;