# HG changeset patch # User Olaf Wintermann # Date 1707384178 -3600 # Node ID 3060a5a1d5fd82da40782a1106e431775f7b6c92 # Parent db263186edf3c714ccfc178f254f88387e0ab11b don't crash when the upload is in progress and the window is closed diff -r db263186edf3 -r 3060a5a1d5fd application/davcontroller.c --- a/application/davcontroller.c Wed Feb 07 17:10:01 2024 +0100 +++ b/application/davcontroller.c Thu Feb 08 10:22:58 2024 +0100 @@ -524,6 +524,9 @@ update_upload_labels(upload); } +static void upload_window_closed(UiEvent *event, void *data) { + // noop, prevents context destruction +} void davbrowser_upload_files(UiObject *ui, DavBrowser *browser, UiFileList files) { if (!browser->sn) { @@ -550,6 +553,7 @@ // create upload progress window cxmutstr wtitle = cx_asprintf("Upload to: %s", ui_get(browser->path)); UiObject *dialog = ui_simple_window(wtitle.ptr, upload); + ui_context_closefunc(dialog->ctx, upload_window_closed, NULL); free(wtitle.ptr); upload->dialog = dialog; ui_window_size(dialog, 550, 120); diff -r db263186edf3 -r 3060a5a1d5fd ui/common/context.c --- a/ui/common/context.c Wed Feb 07 17:10:01 2024 +0100 +++ b/ui/common/context.c Thu Feb 08 10:22:58 2024 +0100 @@ -436,6 +436,10 @@ ctx->close_data = udata; } +UIEXPORT void ui_context_destroy(UiContext *ctx) { + cxMempoolDestroy(ctx->mp); +} + void ui_set_group(UiContext *ctx, int group) { if(cxListFind(ctx->groups, &group) == -1) { diff -r db263186edf3 -r 3060a5a1d5fd ui/ui/toolkit.h --- a/ui/ui/toolkit.h Wed Feb 07 17:10:01 2024 +0100 +++ b/ui/ui/toolkit.h Thu Feb 08 10:22:58 2024 +0100 @@ -371,6 +371,8 @@ UIEXPORT void ui_context_closefunc(UiContext *ctx, ui_callback fnc, void *udata); +UIEXPORT void ui_context_destroy(UiContext *ctx); + UIEXPORT void ui_onstartup(ui_callback f, void *userdata); UIEXPORT void ui_onopen(ui_callback f, void *userdata); UIEXPORT void ui_onexit(ui_callback f, void *userdata); diff -r db263186edf3 -r 3060a5a1d5fd ui/winui/window.cpp --- a/ui/winui/window.cpp Wed Feb 07 17:10:01 2024 +0100 +++ b/ui/winui/window.cpp Thu Feb 08 10:22:58 2024 +0100 @@ -171,7 +171,17 @@ ui_context_add_window_destructor(obj->ctx, obj->wobj); window.Closed([obj](IInspectable const& sender, WindowEventArgs) { - cxMempoolDestroy(obj->ctx->mp); + if (obj->ctx->close_callback) { + UiEvent evt; + evt.obj = obj; + evt.document = obj->ctx->document; + evt.window = obj->window; + evt.eventdata = NULL; + evt.intval = 0; + obj->ctx->close_callback(&evt, obj->ctx->close_data); + } else { + ui_context_destroy(obj->ctx); + } }); obj->container = new UiBoxContainer(grid, UI_BOX_CONTAINER_VBOX, 0, 0);