From 9a081b6809e4acb17a3246b0e93494da5cb33921 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 21 Sep 2023 01:32:01 +0900 Subject: [PATCH] [input] Fix input shutdown order This fixes another segfault on shutdown (not sure just which recent change caused it, but the listener pointer needed clearing) but while fixing the listener issue, I noticed that binding and imt shutdown were in the wrong order with respect to buttons and axes. --- include/QF/input/binding.h | 1 - include/QF/input/imt.h | 1 - libs/input/in_binding.c | 27 ++++++++++++++------------- libs/input/in_button.c | 1 + libs/input/in_common.c | 4 +--- libs/input/in_imt.c | 27 ++++++++++++++------------- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/include/QF/input/binding.h b/include/QF/input/binding.h index d5b6cd6d5..73f61aaa2 100644 --- a/include/QF/input/binding.h +++ b/include/QF/input/binding.h @@ -371,7 +371,6 @@ struct IE_event_s; int IN_Binding_HandleEvent (const struct IE_event_s *ie_event); void IN_Binding_Activate (void); void IN_Binding_Init (void); -void IN_Binding_Shutdown (void); struct plitem_s; void IN_Binding_SaveConfig (struct plitem_s *config); void IN_Binding_LoadConfig (struct plitem_s *config); diff --git a/include/QF/input/imt.h b/include/QF/input/imt.h index 642d24f4a..913bad638 100644 --- a/include/QF/input/imt.h +++ b/include/QF/input/imt.h @@ -130,7 +130,6 @@ void IMT_BindButton (imt_t *imt, int button, const char *binding); bool IMT_ProcessAxis (int axis, int value); bool IMT_ProcessButton (int button, int state); void IMT_Init (void); -void IMT_Shutdown (void); struct plitem_s; void IMT_SaveConfig (struct plitem_s *config); void IMT_SaveAxisConfig (struct plitem_s *axes, int axis_ind, int dev_axis); diff --git a/libs/input/in_binding.c b/libs/input/in_binding.c index 9c8957975..e2c6787f3 100644 --- a/libs/input/in_binding.c +++ b/libs/input/in_binding.c @@ -778,19 +778,8 @@ IN_Binding_Activate (void) IE_Set_Focus (in_binding_handler); } -void -IN_Binding_Init (void) -{ - in_binding_handler = IE_Add_Handler (in_binding_event_handler, 0); - in_keyhelp_handler = IE_Add_Handler (in_keyhelp_event_handler, 0); - - for (bindcmd_t *cmd = in_binding_commands; cmd->name; cmd++) { - Cmd_AddCommand (cmd->name, cmd->func, cmd->desc); - } -} - -void -IN_Binding_Shutdown () +static void +IN_Binding_Shutdown (void *data) { for (in_devbindings_t *db = devbindings_list; db; db = db->next) { clear_connection (db); @@ -802,6 +791,18 @@ IN_Binding_Shutdown () DARRAY_CLEAR (&known_devices); } +void +IN_Binding_Init (void) +{ + Sys_RegisterShutdown (IN_Binding_Shutdown, 0); + in_binding_handler = IE_Add_Handler (in_binding_event_handler, 0); + in_keyhelp_handler = IE_Add_Handler (in_keyhelp_event_handler, 0); + + for (bindcmd_t *cmd = in_binding_commands; cmd->name; cmd++) { + Cmd_AddCommand (cmd->name, cmd->func, cmd->desc); + } +} + void IN_Binding_SaveConfig (plitem_t *config) { diff --git a/libs/input/in_button.c b/libs/input/in_button.c index 74e1551b7..38f2f1ea6 100644 --- a/libs/input/in_button.c +++ b/libs/input/in_button.c @@ -69,6 +69,7 @@ button_free (void *b, void *data) if (rb->button->listeners) { DARRAY_CLEAR (rb->button->listeners); free (rb->button->listeners); + rb->button->listeners = 0; } free (rb); } diff --git a/libs/input/in_common.c b/libs/input/in_common.c index 17fa0686c..896f01dbb 100644 --- a/libs/input/in_common.c +++ b/libs/input/in_common.c @@ -532,15 +532,13 @@ IN_shutdown (void *data) { //JOY_Shutdown (); - Sys_MaskPrintf (SYS_vid, "IN_Shutdown\n"); + Sys_MaskPrintf (SYS_vid, "IN_shutdown\n"); for (size_t i = in_drivers.size; i-- > 0; ) { in_regdriver_t *rd = &in_drivers.a[i]; if (rd->driver.shutdown) { rd->driver.shutdown (rd->data); } } - IN_Binding_Shutdown (); - IMT_Shutdown (); DARRAY_CLEAR (&in_drivers); DARRAY_CLEAR (&in_devices); diff --git a/libs/input/in_imt.c b/libs/input/in_imt.c index 3a4f3488a..c390783ca 100644 --- a/libs/input/in_imt.c +++ b/libs/input/in_imt.c @@ -936,19 +936,8 @@ static imtcmd_t imt_commands[] = { {}, }; -void -IMT_Init (void) -{ - binding_mem = new_memsuper (); - recipe_tab = Hash_NewTable (61, 0, recipe_free, 0, 0); - Hash_SetHashCompare (recipe_tab, recipe_get_hash, recipe_compare); - for (imtcmd_t *cmd = imt_commands; cmd->name; cmd++) { - Cmd_AddCommand (cmd->name, cmd->func, cmd->desc); - } -} - -void -IMT_Shutdown (void) +static void +IMT_Shutdown (void *data) { imt_drop_all_f (); Hash_DelTable (recipe_tab); @@ -960,6 +949,18 @@ IMT_Shutdown (void) DARRAY_CLEAR (&in_contexts); } +void +IMT_Init (void) +{ + Sys_RegisterShutdown (IMT_Shutdown, 0); + binding_mem = new_memsuper (); + recipe_tab = Hash_NewTable (61, 0, recipe_free, 0, 0); + Hash_SetHashCompare (recipe_tab, recipe_get_hash, recipe_compare); + for (imtcmd_t *cmd = imt_commands; cmd->name; cmd++) { + Cmd_AddCommand (cmd->name, cmd->func, cmd->desc); + } +} + void IMT_SaveConfig (plitem_t *config) {