don't crash when the upload is in progress and the window is closed

Thu, 08 Feb 2024 10:22:58 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 08 Feb 2024 10:22:58 +0100
changeset 21
3060a5a1d5fd
parent 20
db263186edf3
child 22
d7942163a2a3

don't crash when the upload is in progress and the window is closed

application/davcontroller.c file | annotate | diff | comparison | revisions
ui/common/context.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
ui/winui/window.cpp file | annotate | diff | comparison | revisions
--- 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);
--- 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) {
--- 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);
--- 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);

mercurial