Use wx_ptr for the splash screen.
authorCarl Hetherington <cth@carlh.net>
Sun, 15 Jan 2023 00:25:27 +0000 (01:25 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 15 Jan 2023 00:25:27 +0000 (01:25 +0100)
src/tools/dcpomatic.cc
src/tools/dcpomatic_editor.cc
src/tools/dcpomatic_kdm.cc
src/tools/dcpomatic_player.cc
src/wx/wx_ptr.h
src/wx/wx_util.cc
src/wx/wx_util.h

index 546306ac4d89bf2f6a42d6a094453aa86f13c2f1..af4576fd5e2daeee848eebc2ed981e00e185c136 100644 (file)
@@ -1728,10 +1728,7 @@ private:
                }
                catch (exception& e)
                {
-                       if (_splash) {
-                               _splash->Destroy ();
-                               _splash = nullptr;
-                       }
+                       _splash.reset();
                        error_dialog (nullptr, wxString::Format ("DCP-o-matic could not start."), std_to_wx(e.what()));
                }
 
@@ -1843,10 +1840,7 @@ private:
 
        void close_splash ()
        {
-               if (_splash) {
-                       _splash->Destroy ();
-                       _splash = nullptr;
-               }
+               _splash.reset();
        }
 
        void config_failed_to_load (Config::LoadFailure what)
@@ -1864,8 +1858,7 @@ private:
                /* Destroy the splash screen here, as otherwise bad things seem to happen (for reasons unknown)
                   when we open our recreate dialog, close it, *then* try to Destroy the splash (the Destroy fails).
                */
-               _splash->Destroy ();
-               _splash = nullptr;
+               _splash.reset();
 
                auto config = Config::instance();
                switch (reason) {
@@ -1934,7 +1927,7 @@ private:
        }
 
        DOMFrame* _frame = nullptr;
-       wxSplashScreen* _splash = nullptr;
+       wx_ptr<wxSplashScreen> _splash;
        shared_ptr<wxTimer> _timer;
        string _film_to_load;
        string _film_to_create;
index 51135ef462372f38750aa22f3452d49ce1a1ac36..8e306551f970bc6790606a6795cef8d52f59ba9f 100644 (file)
@@ -431,7 +431,7 @@ private:
 
        bool OnInit () override
        {
-               wxSplashScreen* splash = nullptr;
+               wx_ptr<wxSplashScreen> splash;
                try {
                        wxInitAllImageHandlers ();
 
index 87a77c6260541c38b649fa71d729e3bfca239e9b..673c54f7839ea0b4122875ae0c980f6b7567fd63 100644 (file)
@@ -770,7 +770,7 @@ private:
 
        bool OnInit () override
        {
-               wxSplashScreen* splash = nullptr;
+               wx_ptr<wxSplashScreen> splash;
 
                try {
                        wxInitAllImageHandlers ();
index 600d1c6b440531aaddfff8df315374283d834054..1808e86fe4d3da7fb450b12c2a7ec0a74166627c 100644 (file)
@@ -898,16 +898,14 @@ private:
                DCPOMATIC_ASSERT (dcp);
 
                auto job = make_shared<VerifyDCPJob>(dcp->directories());
-               auto progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
+               auto progress = make_wx<VerifyDCPProgressDialog>(this, _("DCP-o-matic Player"));
                bool const completed = progress->run (job);
-               progress->Destroy ();
                if (!completed) {
                        return;
                }
 
-               auto d = new VerifyDCPDialog (this, job);
+               auto d = make_wx<VerifyDCPDialog>(this, job);
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void tools_check_for_updates ()
@@ -918,9 +916,8 @@ private:
 
        void tools_timing ()
        {
-               auto d = new TimerDisplay(this, _viewer.state_timer(), _viewer.gets());
+               auto d = make_wx<TimerDisplay>(this, _viewer.state_timer(), _viewer.gets());
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void tools_system_information ()
@@ -934,18 +931,16 @@ private:
 
        void help_about ()
        {
-               auto d = new AboutDialog (this);
+               auto d = make_wx<AboutDialog>(this);
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void help_report_a_problem ()
        {
-               auto d = new ReportProblemDialog (this);
+               auto d = make_wx<ReportProblemDialog>(this);
                if (d->ShowModal () == wxID_OK) {
                        d->report ();
                }
-               d->Destroy ();
        }
 
        void update_checker_state_changed ()
@@ -964,9 +959,8 @@ private:
                }
 
                if (uc->state() == UpdateChecker::State::YES) {
-                       auto dialog = new UpdateDialog (this, uc->stable (), uc->test ());
+                       auto dialog = make_wx<UpdateDialog>(this, uc->stable (), uc->test ());
                        dialog->ShowModal ();
-                       dialog->Destroy ();
                } else if (uc->state() == UpdateChecker::State::FAILED) {
                        error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
                } else {
@@ -1168,7 +1162,7 @@ private:
 
        bool OnInit () override
        {
-               wxSplashScreen* splash = nullptr;
+               wx_ptr<wxSplashScreen> splash;
                try {
                        wxInitAllImageHandlers ();
 
index 96459183ee070832a3e887e53d9def687f490399..24bccb0438a517b59a9c9a8b4d70c9149a87380c 100644 (file)
@@ -62,11 +62,34 @@ public:
                }
        }
 
-       T* operator->() {
+       wx_ptr& operator=(T* ptr)
+       {
+               if (_wx) {
+                       _wx->Destroy();
+               }
+               _wx = ptr;
+               return *this;
+       }
+
+       T* operator->()
+       {
                DCPOMATIC_ASSERT(_wx);
                return _wx;
        }
 
+       operator bool() const
+       {
+               return _wx != nullptr;
+       }
+
+       void reset()
+       {
+               if (_wx) {
+                       _wx->Destroy();
+                       _wx = nullptr;
+               }
+       }
+
        template <typename... Args>
        void reset(Args&&... args)
        {
index d264f8b20b761cea3c3a335a016112e0cbc33cc9..e600b63c89c4506e4b161b3b1f5a64617df1a8e8 100644 (file)
@@ -537,10 +537,11 @@ setup_audio_channels_choice (wxChoice* choice, int minimum)
 }
 
 
-wxSplashScreen *
+wx_ptr<wxSplashScreen>
 maybe_show_splash ()
 {
-       wxSplashScreen* splash = nullptr;
+       wx_ptr<wxSplashScreen> splash;
+
        try {
                wxBitmap bitmap;
                if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) {
@@ -554,9 +555,9 @@ maybe_show_splash ()
                        }
 #ifdef DCPOMATIC_WINDOWS
                        /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */
-                       splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
+                       splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
 #else
-                       splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1);
+                       splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1);
 #endif
                        wxYield ();
                }
index 5ef221b15f89b2943881e9cab274b626f2bc6933..be3be0d1ad5cce322117f064135f7f00cbb74703 100644 (file)
@@ -28,6 +28,7 @@
 #define DCPOMATIC_WX_UTIL_H
 
 
+#include "wx_ptr.h"
 #include "lib/config.h"
 #include "lib/dcpomatic_time.h"
 #include <dcp/warnings.h>
@@ -116,7 +117,7 @@ extern wxString context_translation (wxString);
 extern std::string string_client_data (wxClientData* o);
 extern wxString time_to_timecode (dcpomatic::DCPTime t, double fps);
 extern void setup_audio_channels_choice (wxChoice* choice, int minimum);
-extern wxSplashScreen* maybe_show_splash ();
+extern wx_ptr<wxSplashScreen> maybe_show_splash();
 extern double calculate_mark_interval (double start);
 extern bool display_progress (wxString title, wxString task);
 extern bool report_errors_from_last_job (wxWindow* parent);