[Bugfix] crashes on usb unplug, extra text on USB screen, viewportmgr ovfl on sim

make _lists_uiviewport_update_callback a oneshot
and reset it each call of list_do_action_timeout()

block multiple runs of gui_usb_screen_run() in the sim

Change-Id: I0c0429c42622c82bcf481ad13efdc47e9055a1bb
This commit is contained in:
William Wilgus 2024-07-21 11:53:25 -04:00 committed by William Wilgus
parent 2bb9323de8
commit 7720b0c4e4
2 changed files with 23 additions and 19 deletions

View file

@ -60,12 +60,8 @@ static bool list_is_dirty(struct gui_synclist *list)
static void list_force_reinit(unsigned short id, void *param, void *last_dirty_tick) static void list_force_reinit(unsigned short id, void *param, void *last_dirty_tick)
{ {
(void)id;
(void)param; (void)param;
if (id == SYS_EVENT_USB_INSERTED) /* Disable the skin redraw callback -- Data may not be valid after USB unplug*/
{
current_lists = NULL;
return;
}
*(int *)last_dirty_tick = current_tick; *(int *)last_dirty_tick = current_tick;
} }
@ -73,7 +69,6 @@ void list_init(void)
{ {
last_dirty_tick = current_tick; last_dirty_tick = current_tick;
add_event_ex(GUI_EVENT_THEME_CHANGED, false, list_force_reinit, &last_dirty_tick); add_event_ex(GUI_EVENT_THEME_CHANGED, false, list_force_reinit, &last_dirty_tick);
add_event_ex(SYS_EVENT_USB_INSERTED, false, list_force_reinit, NULL);
} }
static void list_init_viewports(struct gui_synclist *list) static void list_init_viewports(struct gui_synclist *list)
@ -166,7 +161,6 @@ void gui_synclist_init(struct gui_synclist * gui_list,
gui_list->nb_items = 0; gui_list->nb_items = 0;
gui_list->selected_item = 0; gui_list->selected_item = 0;
gui_synclist_init_display_settings(gui_list); gui_synclist_init_display_settings(gui_list);
#ifdef HAVE_TOUCHSCREEN #ifdef HAVE_TOUCHSCREEN
gui_list->y_pos = 0; gui_list->y_pos = 0;
#endif #endif
@ -592,15 +586,19 @@ bool gui_synclist_keyclick_callback(int action, void* data)
* loop. * loop.
* *
* The GUI_EVENT_NEED_UI_UPDATE event is registered for in list_do_action_timeout() * The GUI_EVENT_NEED_UI_UPDATE event is registered for in list_do_action_timeout()
* and unregistered in gui_synclict_do_button(). This is done because * as a oneshot and current_lists updated. later current_lists is set to NULL
* if something is using the list UI they *must* be calling those * in gui_synclist_do_button() effectively disabling the callback.
* This is done because if something is using the list UI they *must* be calling those
* two functions in the correct order or the list wont work. * two functions in the correct order or the list wont work.
*/ */
static bool ui_update_event_registered = false;
static void _lists_uiviewport_update_callback(unsigned short id, void *data) static void _lists_uiviewport_update_callback(unsigned short id,
void *data, void *userdata)
{ {
(void)id; (void)id;
(void)data; (void)data;
(void)userdata;
if (current_lists) if (current_lists)
gui_synclist_draw(current_lists); gui_synclist_draw(current_lists);
} }
@ -774,13 +772,8 @@ int list_do_action_timeout(struct gui_synclist *lists, int timeout)
/* Returns the lowest of timeout or the delay until a postponed /* Returns the lowest of timeout or the delay until a postponed
scheduled announcement is due (if any). */ scheduled announcement is due (if any). */
{ {
if (lists != current_lists) add_event_ex(GUI_EVENT_NEED_UI_UPDATE, true, _lists_uiviewport_update_callback, NULL);
{
if (!ui_update_event_registered)
ui_update_event_registered =
add_event(GUI_EVENT_NEED_UI_UPDATE, _lists_uiviewport_update_callback);
current_lists = lists; current_lists = lists;
}
if(lists->scheduled_talk_tick) if(lists->scheduled_talk_tick)
{ {
long delay = lists->scheduled_talk_tick -current_tick +1; long delay = lists->scheduled_talk_tick -current_tick +1;
@ -949,8 +942,10 @@ bool simplelist_show_list(struct simplelist_info *info)
old_line_count = simplelist_line_count; old_line_count = simplelist_line_count;
} }
else if(default_event_handler(action) == SYS_USB_CONNECTED) else if(default_event_handler(action) == SYS_USB_CONNECTED)
{
return true; return true;
} }
}
talk_shutup(); talk_shutup();
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR

View file

@ -243,7 +243,13 @@ static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar)
void gui_usb_screen_run(bool early_usb) void gui_usb_screen_run(bool early_usb)
{ {
(void) early_usb; #ifdef SIMULATOR /* the sim allows toggling USB fast enough to overflow viewportmanagers stack */
static bool in_usb_screen = false;
if (in_usb_screen)
return;
in_usb_screen = true;
#endif
struct usb_screen_vps_t usb_screen_vps_ar[NB_SCREENS]; struct usb_screen_vps_t usb_screen_vps_ar[NB_SCREENS];
#if defined HAVE_TOUCHSCREEN #if defined HAVE_TOUCHSCREEN
enum touchscreen_mode old_mode = touchscreen_get_mode(); enum touchscreen_mode old_mode = touchscreen_get_mode();
@ -334,4 +340,7 @@ void gui_usb_screen_run(bool early_usb)
} }
pop_current_activity(); pop_current_activity();
#ifdef SIMULATOR
in_usb_screen = false;
#endif
} }