From c90f24d2e024de9febc463fb8dd94cc82a557196 Mon Sep 17 00:00:00 2001 From: Dethrace Engineering Department <78985374+dethrace-labs@users.noreply.github.com> Date: Tue, 2 May 2023 13:01:28 +1200 Subject: [PATCH] Fixes missing fatal error messages (#316) * fixes missing fatal error messages --- src/DETHRACE/pc-win95/win95sys.c | 4 ++-- src/harness/include/harness/hooks.h | 2 ++ src/harness/include/harness/win95_polyfill_defs.h | 2 ++ src/harness/platforms/sdl_opengl.c | 7 +++++++ src/harness/win95/polyfill.c | 4 +++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/DETHRACE/pc-win95/win95sys.c b/src/DETHRACE/pc-win95/win95sys.c index d57278d2..e81a72a9 100644 --- a/src/DETHRACE/pc-win95/win95sys.c +++ b/src/DETHRACE/pc-win95/win95sys.c @@ -341,7 +341,7 @@ void PDFatalError(char* pThe_str) { LOG_TRACE("(\"%s\")", pThe_str); dr_dprintf("FATAL ERROR: %s", pThe_str); - Win32FatalError(pThe_str, NULL); + Win32FatalError(pThe_str, ""); } void Win32FatalError(char* pStr_1, char* pStr_2) { @@ -438,7 +438,7 @@ void PDShutdownSystem() { SendMessageA_(HWND_BROADCAST, 0x18u, 1u, 0); if (gWin32_show_fatal_error_message) { dr_dprintf("Displaying fatal error..."); - MessageBoxA_(0, gWin32_fatal_error_message, "Carmageddon Fatal Error", 0x10u); + MessageBoxA_(0, gWin32_fatal_error_message, "Carmageddon Fatal Error", MB_ICONERROR); } if (gWin32_hwnd) { dr_dprintf("Destroying window..."); diff --git a/src/harness/include/harness/hooks.h b/src/harness/include/harness/hooks.h index b5e57743..5817f9a8 100644 --- a/src/harness/include/harness/hooks.h +++ b/src/harness/include/harness/hooks.h @@ -58,6 +58,8 @@ typedef struct tHarness_platform { uint32_t (*GetTicks)(void); // Swap window void (*SwapWindow)(void); + // Show error message + int (*ShowErrorMessage)(void* window, char* text, char* caption); } tHarness_platform; diff --git a/src/harness/include/harness/win95_polyfill_defs.h b/src/harness/include/harness/win95_polyfill_defs.h index b95b35a3..85907bb2 100644 --- a/src/harness/include/harness/win95_polyfill_defs.h +++ b/src/harness/include/harness/win95_polyfill_defs.h @@ -21,6 +21,8 @@ typedef void* HANDLE_; #define WM_QUIT 0x0012 +#define MB_ICONERROR 0x00000010 + typedef struct _MEMORYSTATUS_ { uint32_t dwLength; uint32_t dwMemoryLoad; diff --git a/src/harness/platforms/sdl_opengl.c b/src/harness/platforms/sdl_opengl.c index 29eb7208..8a6af98e 100644 --- a/src/harness/platforms/sdl_opengl.c +++ b/src/harness/platforms/sdl_opengl.c @@ -219,6 +219,12 @@ static void set_palette(PALETTEENTRY_* pal) { GLRenderer_SetPalette((uint8_t*)pal); } +int show_error_message(void* window, char* text, char* caption) { + fprintf(stderr, "%s", text); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption, text, window); + return 0; +} + void Harness_Platform_Init(tHarness_platform* platform) { platform->ProcessWindowMessages = get_and_handle_message; platform->Sleep = SDL_Delay; @@ -232,6 +238,7 @@ void Harness_Platform_Init(tHarness_platform* platform) { platform->GetMousePosition = get_mouse_position; platform->GetMouseButtons = get_mouse_buttons; platform->DestroyWindow = destroy_window; + platform->ShowErrorMessage = show_error_message; platform->Renderer_BufferModel = GLRenderer_BufferModel; platform->Renderer_BufferMaterial = GLRenderer_BufferMaterial; diff --git a/src/harness/win95/polyfill.c b/src/harness/win95/polyfill.c index f8d1fde4..56752198 100644 --- a/src/harness/win95/polyfill.c +++ b/src/harness/win95/polyfill.c @@ -187,7 +187,9 @@ int SendMessageA_(void* hWnd, unsigned int Msg, unsigned int wParam, long lParam } int MessageBoxA_(void* hWnd, char* lpText, char* lpCaption, unsigned int uType) { - return 0; + // only ever used for errors + assert(uType == MB_ICONERROR); + return gHarness_platform.ShowErrorMessage(hWnd, lpText, lpCaption); } int DestroyWindow_(void* hWnd) {