[Bf-blender-cvs] [178c1848254] master: GHOST/Wayland: define a log handler to help tracking down errors

Campbell Barton noreply at git.blender.org
Fri Jun 10 10:44:22 CEST 2022


Commit: 178c18482546ba7a9e8c7bfdf2164ef6c5993d1a
Author: Campbell Barton
Date:   Fri Jun 10 15:15:38 2022 +1000
Branches: master
https://developer.blender.org/rB178c18482546ba7a9e8c7bfdf2164ef6c5993d1a

GHOST/Wayland: define a log handler to help tracking down errors

Many errors involving mis-use or unexpected situations report an
error and close Blender's window buy don't crash, making it difficult
to track down when the error occurs.

Define an error handler prints the error and a back-trace,
it can also be useful for setting a break-point

===================================================================

M	intern/ghost/intern/GHOST_SystemWayland.cpp

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 05f2c5d1177..c446963c082 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -171,6 +171,23 @@ struct display_t {
 
 static GHOST_WindowManager *window_manager = nullptr;
 
+/**
+ * Callback for WAYLAND to run when there is an error.
+ *
+ * \note It's useful to set a break-point on this function as some errors are fatal
+ * (for all intents and purposes) but don't crash the process.
+ */
+static void ghost_wayland_log_handler(const char *msg, va_list arg)
+{
+  fprintf(stderr, "GHOST/Wayland: ");
+  vfprintf(stderr, msg, arg); /* Includes newline. */
+
+  GHOST_TBacktraceFn backtrace_fn = GHOST_ISystem::getBacktraceFn();
+  if (backtrace_fn) {
+    backtrace_fn(stderr); /* Includes newline. */
+  }
+}
+
 static void display_destroy(display_t *d)
 {
   if (d->data_device_manager) {
@@ -1503,6 +1520,8 @@ static const struct wl_registry_listener registry_listener = {
 
 GHOST_SystemWayland::GHOST_SystemWayland() : GHOST_System(), d(new display_t)
 {
+  wl_log_set_handler_client(ghost_wayland_log_handler);
+
   d->system = this;
   /* Connect to the Wayland server. */
   d->display = wl_display_connect(nullptr);



More information about the Bf-blender-cvs mailing list