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
This commit is contained in:
Campbell Barton
2022-06-10 15:15:38 +10:00
parent 2601b9832d
commit 178c184825

View File

@@ -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);