diff --git a/ext/libstrawberry-common/core/lazy.h b/ext/libstrawberry-common/core/lazy.h index 53ee4b1ef..90f1f7394 100644 --- a/ext/libstrawberry-common/core/lazy.h +++ b/ext/libstrawberry-common/core/lazy.h @@ -21,7 +21,7 @@ #include #include -// Helper for lazy initialisation of objects. +// Helper for lazy initialization of objects. // Usage: // Lazy my_lazy_object([]() { return new Foo; }); @@ -48,19 +48,18 @@ class Lazy { // Returns true if the object is not yet initialised. explicit operator bool() const { return ptr_; } - // Deletes the underlying object and will re-run the initialisation function - // if the object is requested again. - void reset() { ptr_.reset(nullptr); } + // Deletes the underlying object and will re-run the initialisation function if the object is requested again. + void reset() { ptr_.reset(); } private: void CheckInitialised() const { if (!ptr_) { - ptr_.reset(init_()); + ptr_.reset(init_(), [](T*obj) { obj->deleteLater(); }); } } const std::function init_; - mutable std::unique_ptr ptr_; + mutable std::shared_ptr ptr_; }; #endif // LAZY_H diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 700c1df6e..cc14b2145 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -1087,6 +1087,9 @@ void MainWindow::SaveSettings() { void MainWindow::Exit() { + // Make sure Settings dialog is destroyed first. + settings_dialog_.reset(); + ++exit_count_; SaveSettings();