fix crash when closing the settings window

Sun, 27 Oct 2024 19:19:51 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 Oct 2024 19:19:51 +0100
changeset 61
eb63af2f2bdd
parent 60
ee4e4742391e
child 62
dbde5e038ea9

fix crash when closing the settings window

application/settings.c file | annotate | diff | comparison | revisions
--- a/application/settings.c	Sun Oct 27 18:24:37 2024 +0100
+++ b/application/settings.c	Sun Oct 27 19:19:51 2024 +0100
@@ -86,7 +86,7 @@
     ui_close(event->obj);
 }
 
-void settings_cancel(UiEvent *event, void *userdata) {
+void settings_close(UiEvent *event, void *userdata) {
     SettingsWindow *settings = event->window;
     if(settings->config_saved) {
         // function was called as context closefunc by ui_close
@@ -95,9 +95,11 @@
         return;
     }
     dav_config_free(settings->config);
-    if(userdata) {
-        ui_close(event->obj);
-    }
+}
+
+void settings_cancel(UiEvent *event, void *userdata) {
+    SettingsWindow *settings = event->window;
+    ui_close(event->obj);
 }
 
 void settings_window_open() {
@@ -107,7 +109,7 @@
     }
     
     UiObject *obj = ui_simple_window("Settings", NULL);
-    ui_context_closefunc(obj->ctx, settings_cancel, NULL);
+    ui_context_closefunc(obj->ctx, settings_close, NULL);
     SettingsWindow *wdata = ui_malloc(obj->ctx, sizeof(SettingsWindow));
     wdata->config = config;
     obj->window = wdata;
@@ -246,7 +248,7 @@
     }
     
     ui_hbox(obj, .fill = UI_OFF, .margin = 10) {
-        ui_button(obj, .label = "Cancel", .onclick = settings_cancel, .onclickdata = "close");
+        ui_button(obj, .label = "Cancel", .onclick = settings_cancel);
         ui_label(obj, .fill = UI_ON);
         ui_button(obj, .label = "Save", .onclick = settings_ok);
     }

mercurial