From 91f56e45665e0ae940553acc1d0013adec970712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 17 Aug 2022 18:21:20 +0200 Subject: Install terminate handler before initialization of globals. --- c/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'c') diff --git a/c/main.cpp b/c/main.cpp index 7f7ea9b..7a3e6a2 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -21,6 +21,10 @@ #define YMAIN CW_USEDEFAULT #endif +/* Exit gracefully on uncaught exception. */ +static void OnTerminate() noexcept; +static auto unused = std::set_terminate(OnTerminate); + /* main.cpp defines all global (non-template) variables used in the * program. `extern' is used to access them from other files, when * need be. */ @@ -72,7 +76,7 @@ static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); /* Try to style application according to current Windows theme. */ static void UpdateTheme(); -static void OnTerminate() noexcept +void OnTerminate() noexcept { const wchar_t* what = L"an exception"; WcharPtr why; @@ -104,9 +108,6 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons { setbuf(stdout, nullptr); - /* Exit gracefully on uncaught exception. */ - std::set_terminate(OnTerminate); - /* Initialize Prolog. */ const char* argv[] = {"EpisodeBrowser", nullptr}; if (!PL_initialise(1, const_cast(argv))) -- cgit v1.2.3