Fix crash on startup on macOS.
[dcpomatic.git] / src / wx / wx_util.cc
index 192724b13328ba496a87ab38198b14da71efe16e..8ef32fca37858e6c3265c37cdb8634e1f28d04c7 100644 (file)
 
 */
 
+
 /** @file src/wx/wx_util.cc
  *  @brief Some utility functions and classes.
  */
 
-#include "wx_util.h"
+
 #include "file_picker_ctrl.h"
-#include "static_text.h"
 #include "password_entry.h"
+#include "static_text.h"
+#include "wx_util.h"
 #include "lib/config.h"
-#include "lib/job_manager.h"
-#include "lib/util.h"
 #include "lib/cross.h"
 #include "lib/job.h"
+#include "lib/job_manager.h"
+#include "lib/util.h"
+#include "lib/version.h"
 #include "lib/warnings.h"
 #include <dcp/locale_convert.h>
 DCPOMATIC_DISABLE_WARNINGS
@@ -42,6 +45,7 @@ DCPOMATIC_DISABLE_WARNINGS
 DCPOMATIC_ENABLE_WARNINGS
 #include <boost/thread.hpp>
 
+
 using std::string;
 using std::vector;
 using std::pair;
@@ -50,6 +54,7 @@ using boost::optional;
 using dcp::locale_convert;
 using namespace dcpomatic;
 
+
 wxStaticText *
 #ifdef __WXOSX__
 create_label (wxWindow* p, wxString t, bool left)
@@ -476,6 +481,7 @@ setup_audio_channels_choice (wxChoice* choice, int minimum)
        checked_set (choice, items);
 }
 
+
 wxSplashScreen *
 maybe_show_splash ()
 {
@@ -483,7 +489,20 @@ maybe_show_splash ()
        try {
                wxBitmap bitmap;
                if (bitmap.LoadFile(bitmap_path("splash"), wxBITMAP_TYPE_PNG)) {
+                       {
+                               /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */
+                               wxMemoryDC dc(bitmap);
+                               auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit);
+                               auto screen_size = dc.GetSize();
+                               auto text_size = dc.GetTextExtent(version);
+                               dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236);
+                       }
+#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);
+#else
                        splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1);
+#endif
                        wxYield ();
                }
        } catch (boost::filesystem::filesystem_error& e) {