From 8c1351a3631edfcd5f3582c36a296d16ad351b44 Mon Sep 17 00:00:00 2001 From: dpjudas Date: Sun, 16 Jun 2024 01:19:09 +0200 Subject: [PATCH] Use a win32 message box if a fatal error happens before we got the chance to initialize zwidget's resources --- src/common/platform/win32/i_mainwindow.cpp | 12 +++++++++++- src/common/widgets/widgetresourcedata.cpp | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/common/platform/win32/i_mainwindow.cpp b/src/common/platform/win32/i_mainwindow.cpp index 95dda5031..abe46df5e 100644 --- a/src/common/platform/win32/i_mainwindow.cpp +++ b/src/common/platform/win32/i_mainwindow.cpp @@ -20,6 +20,8 @@ #pragma comment(lib, "dwmapi.lib") +bool IsZWidgetAvailable(); + MainWindow mainwindow; void MainWindow::Create(const FString& caption, int x, int y, int width, int height) @@ -115,7 +117,15 @@ void MainWindow::ShowErrorPane(const char* text) for (const FString& line : bufferedConsoleStuff) alltext.append(line.GetChars(), line.Len()); - restartrequest = ErrorWindow::ExecModal(text, alltext); + if (IsZWidgetAvailable()) + { + restartrequest = ErrorWindow::ExecModal(text, alltext); + } + else // We are aborting before we even got to load zdoom.pk3 + { + MessageBoxA(0, text, "Fatal Error", MB_OK | MB_ICONERROR); + restartrequest = false; + } } void MainWindow::ShowNetStartPane(const char* message, int maxpos) diff --git a/src/common/widgets/widgetresourcedata.cpp b/src/common/widgets/widgetresourcedata.cpp index 522f4ff1e..849b6d553 100644 --- a/src/common/widgets/widgetresourcedata.cpp +++ b/src/common/widgets/widgetresourcedata.cpp @@ -12,6 +12,11 @@ FResourceFile* WidgetResources; +bool IsZWidgetAvailable() +{ + return WidgetResources; +} + void InitWidgetResources(const char* filename) { WidgetResources = FResourceFile::OpenResourceFile(filename); @@ -23,11 +28,15 @@ void InitWidgetResources(const char* filename) void CloseWidgetResources() { - if (WidgetResources) delete WidgetResources; + delete WidgetResources; + WidgetResources = nullptr; } static std::vector LoadFile(const char* name) { + if (!WidgetResources) + I_FatalError("InitWidgetResources has not been called"); + auto lump = WidgetResources->FindEntry(name); if (lump == -1) I_FatalError("Unable to find %s", name);