From 3a6210b154fda3969e1b217723a978eff4dd1186 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Wed, 9 Oct 2024 18:42:26 +0200 Subject: [PATCH] Hopefully make macOS port compatible with SDL3 .. mostly by not making it use SDL_main.h, because it implements its own SDL main functionality anyway. However, I have no way to test this code and as long as SDL3 is not in homebrew testing it in the CI build isn't easy either. --- neo/sys/osx/DOOMController.mm | 14 +++++++++----- neo/sys/osx/SDLMain.m | 10 +++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/neo/sys/osx/DOOMController.mm b/neo/sys/osx/DOOMController.mm index 9da67edc..01e43586 100644 --- a/neo/sys/osx/DOOMController.mm +++ b/neo/sys/osx/DOOMController.mm @@ -32,9 +32,6 @@ If you have questions concerning this license or the applicable additional terms #include #include #include - -#include - #include "sys/platform.h" #include @@ -45,6 +42,11 @@ If you have questions concerning this license or the applicable additional terms #include "sys/posix/posix_public.h" +// usually the following would be from SDL_main.h, +// but this way we should be able to avoid that header +// for better compatibility between SDL1.2 to SDL3 +extern "C" int SDL_main( int argc, char *argv[] ); + static char base_path[MAXPATHLEN]; static char exe_path[MAXPATHLEN]; static char save_path[MAXPATHLEN]; @@ -194,13 +196,15 @@ int SDL_main( int argc, char *argv[] ) { Sys_Error("Could not access application resources"); // DG: set exe_path so Posix_InitSignalHandlers() can call Posix_GetExePath() - SDL_strlcpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cStringUsingEncoding:NSUTF8StringEncoding ], sizeof(exe_path)); + strncpy(exe_path, [ [ [ NSBundle mainBundle ] bundlePath ] cStringUsingEncoding:NSUTF8StringEncoding ], sizeof(exe_path)-1); + exe_path[sizeof(exe_path)-1] = '\0'; // same for save_path for Posix_GetSavePath() D3_snprintfC99(save_path, sizeof(save_path), "%s/Library/Application Support/dhewm3", [NSHomeDirectory() cStringUsingEncoding:NSUTF8StringEncoding]); // and preinitializing basepath is easy enough so do that as well { char* snap; - SDL_strlcpy(base_path, exe_path, sizeof(base_path)); + strncpy(base_path, exe_path, sizeof(base_path)-1); + base_path[sizeof(base_path)-1] = '\0'; snap = strrchr(base_path, '/'); if (snap) *snap = '\0'; diff --git a/neo/sys/osx/SDLMain.m b/neo/sys/osx/SDLMain.m index ce6a7bd1..6a0aa612 100644 --- a/neo/sys/osx/SDLMain.m +++ b/neo/sys/osx/SDLMain.m @@ -10,7 +10,15 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" #endif -#include "SDL.h" +#ifdef D3_SDL3 + #include + // as SDL.h doesn't implicitly include SDL_main.h anymore, + // declare SDL_main() here. I think it's the only part of SDL_main.h we used, + // we implement it in DOOMController.mm an call it here in applicationDidFinishLaunching + extern "C" int SDL_main( int argc, char *argv[] ); +#else // SDL2 and SDL1.2 + #include "SDL.h" +#endif #include "SDLMain.h" #include /* for MAXPATHLEN */ #include