Set the cocoa uncaught exception handler during glfw init not at module import time
This commit is contained in:
parent
a9f1928913
commit
b5467b8e26
@ -906,6 +906,17 @@ cocoa_system_beep(const char *path) {
|
||||
else NSBeep();
|
||||
}
|
||||
|
||||
static void
|
||||
uncaughtExceptionHandler(NSException *exception) {
|
||||
log_error("Unhandled exception in Cocoa: %s", [[exception description] UTF8String]);
|
||||
log_error("Stack trace:\n%s", [[exception.callStackSymbols description] UTF8String]);
|
||||
}
|
||||
|
||||
void
|
||||
cocoa_set_uncaught_exception_handler(void) {
|
||||
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
|
||||
}
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
{"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""},
|
||||
{"cocoa_set_global_shortcut", (PyCFunction)cocoa_set_global_shortcut, METH_VARARGS, ""},
|
||||
@ -915,17 +926,10 @@ static PyMethodDef module_methods[] = {
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
uncaughtExceptionHandler(NSException *exception) {
|
||||
log_error("Unhandled exception in Cocoa: %s", [[exception description] UTF8String]);
|
||||
log_error("Stack trace:\n%s", [[exception.callStackSymbols description] UTF8String]);
|
||||
}
|
||||
|
||||
bool
|
||||
init_cocoa(PyObject *module) {
|
||||
memset(&global_shortcuts, 0, sizeof(global_shortcuts));
|
||||
if (PyModule_AddFunctions(module, module_methods) != 0) return false;
|
||||
register_at_exit_cleanup_func(COCOA_CLEANUP_FUNC, cleanup);
|
||||
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ extern void cocoa_set_titlebar_appearance(void *w, unsigned int theme);
|
||||
extern void cocoa_set_titlebar_color(void *w, color_type color);
|
||||
extern bool cocoa_alt_option_key_pressed(unsigned long);
|
||||
extern void cocoa_toggle_secure_keyboard_entry(void);
|
||||
extern void cocoa_set_uncaught_exception_handler(void);
|
||||
extern void cocoa_update_menu_bar_title(PyObject*);
|
||||
extern size_t cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz);
|
||||
extern monotonic_t cocoa_cursor_blink_interval(void);
|
||||
@ -1037,6 +1038,9 @@ glfw_init(PyObject UNUSED *self, PyObject *args) {
|
||||
const char* path;
|
||||
int debug_keyboard = 0, debug_rendering = 0;
|
||||
if (!PyArg_ParseTuple(args, "s|pp", &path, &debug_keyboard, &debug_rendering)) return NULL;
|
||||
#ifdef __APPLE__
|
||||
cocoa_set_uncaught_exception_handler();
|
||||
#endif
|
||||
const char* err = load_glfw(path);
|
||||
if (err) { PyErr_SetString(PyExc_RuntimeError, err); return NULL; }
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user