libobs: Disallow overwriting the crash handler

Setting a new crash handler overwrites the existing one. This is not
desirable.
This commit is contained in:
Sebastian Beckmann
2025-09-18 23:40:53 +02:00
committed by Ryan Foster
parent 1b41b44b50
commit 77fb5b4bc7
2 changed files with 9 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ Logging Functions
.. function:: void base_set_crash_handler(void (*handler)(const char *, va_list, void *), void *param)
Sets the current crash handler.
This may only be set once.
---------------------

View File

@@ -19,6 +19,7 @@
#include "c99defs.h"
#include "base.h"
#include "threading.h"
static int crashing = 0;
static void *log_param = NULL;
@@ -83,6 +84,13 @@ void base_set_log_handler(log_handler_t handler, void *param)
void base_set_crash_handler(void (*handler)(const char *, va_list, void *), void *param)
{
static bool non_default_handler_set = false;
if (os_atomic_exchange_bool(&non_default_handler_set, true)) {
blog(LOG_WARNING, "Tried to set a crash handler when one already exists.");
return;
}
crash_param = param;
crash_handler = handler;
}