[niepce] ui: don't crash on edit labels if there is no library client



commit d9bd28d609fe23bebe6135276237a3a061805735
Author: Hubert Figuiere <hub figuiere net>
Date:   Mon Sep 26 18:54:25 2022 -0400

    ui: don't crash on edit labels if there is no library client
    
    - it's an error, hence the assert
    - at this time the root cause hasn't been fixed

 src/niepce/ui/niepcewindow.cpp | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/niepce/ui/niepcewindow.cpp b/src/niepce/ui/niepcewindow.cpp
index 08887443..7014c560 100644
--- a/src/niepce/ui/niepcewindow.cpp
+++ b/src/niepce/ui/niepcewindow.cpp
@@ -386,12 +386,17 @@ bool NiepceWindow::open_library(const std::string & libMoniker)
 void NiepceWindow::on_action_edit_labels()
 {
     DBG_OUT("edit labels");
-    // get the labels.
-    m_editlabel_dialog = EditLabels::Ptr(new EditLabels(getLibraryClient()));
-    // XXX I do have serious doubt on the safety of this
-    m_editlabel_dialog->run_modal(shared_frame_ptr(), [this] (int) {
-        m_editlabel_dialog.reset((EditLabels*)nullptr);
-    });
+    auto libclient = getLibraryClient();
+    DBG_ASSERT(!!getLibraryClient(), "No library client");
+    // This is an error. Just make it safe.
+    if (libclient) {
+        // get the labels.
+        m_editlabel_dialog = EditLabels::Ptr(new EditLabels(libclient));
+        // XXX I do have serious doubt on the safety of this
+        m_editlabel_dialog->run_modal(shared_frame_ptr(), [this] (int) {
+            m_editlabel_dialog.reset((EditLabels*)nullptr);
+        });
+    }
 }
 
 void NiepceWindow::on_action_edit_delete()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]