@@ -689,6 +689,7 @@ static void _webui_window_close_ui(_webui_window_t* win);
689689static void _webui_window_task_count(_webui_window_t* win, int delta);
690690static size_t _webui_window_task_get(_webui_window_t* win);
691691static void _webui_window_wait_for_tasks(_webui_window_t* win);
692+ static void _webui_window_clear_clients(_webui_window_t* win);
692693static void _webui_condition_init(webui_condition_t* cond);
693694static void _webui_condition_wait(webui_condition_t* cond, webui_mutex_t* mutex);
694695static void _webui_condition_signal(webui_condition_t* cond);
@@ -6625,6 +6626,26 @@ static size_t _webui_window_task_get(_webui_window_t* win) {
66256626 return count;
66266627}
66276628
6629+ static void _webui_window_clear_clients(_webui_window_t* win) {
6630+
6631+ _webui_mutex_lock(&_webui.mutex_client);
6632+ for (size_t i = 0; i < WEBUI_MAX_IDS; i++) {
6633+ if ((_webui.clients[i] != NULL) && (_webui.clients_win_num[i] == win->num)) {
6634+ #ifdef WEBUI_LOG
6635+ _webui_log_debug("[Core]\t\t_webui_window_clear_clients([%zu]) -> Removing client #%zu\n", win->num, i);
6636+ #endif
6637+ _webui.clients[i] = NULL;
6638+ _webui.clients_win_num[i] = 0;
6639+ _webui_mutex_is_multi_client_token_valid(win, WEBUI_MUTEX_SET_FALSE, (int)i);
6640+ }
6641+ }
6642+ win->single_client = NULL;
6643+ win->clients_count = 0;
6644+ _webui_mutex_unlock(&_webui.mutex_client);
6645+
6646+ _webui_mutex_is_single_client_token_valid(win, WEBUI_MUTEX_SET_FALSE);
6647+ }
6648+
66286649static void _webui_window_wait_for_tasks(_webui_window_t* win) {
66296650
66306651 // Wait for the in-flight event tasks of this window to retire, so no
@@ -11177,6 +11198,9 @@ static WEBUI_THREAD_SERVER_START {
1117711198 http_ctx = NULL;
1117811199 _webui_mutex_is_server_running(win, WEBUI_MUTEX_SET_FALSE);
1117911200
11201+ // The clients of the old server are gone with it
11202+ _webui_window_clear_clients(win);
11203+
1118011204 // Apply the port settings
1118111205 size_t new_port = (win->custom_server_port > 0 ? win->custom_server_port : win->server_port);
1118211206 if (new_port != win->server_port) {
@@ -11608,6 +11632,9 @@ static WEBUI_THREAD_SERVER_START {
1160811632 // Mutex
1160911633 _webui_mutex_is_server_running(win, WEBUI_MUTEX_SET_FALSE);
1161011634
11635+ // The clients of this window are gone with its server
11636+ _webui_window_clear_clients(win);
11637+
1161111638 // Free Port
1161211639 if (server_port != NULL) {
1161311640 _webui_free_port(win->server_port);
0 commit comments