From bee81e9723bb796270960bb72745976353cba1e4 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sat, 21 Oct 2023 19:39:02 +0300 Subject: [PATCH] engine: Make SDL_GetBasePath error not fatal --- engine/common/host.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/engine/common/host.c b/engine/common/host.c index 6c3e11cd..66e0625d 100644 --- a/engine/common/host.c +++ b/engine/common/host.c @@ -1025,12 +1025,21 @@ void Host_InitCommon( int argc, char **argv, const char *progname, qboolean bCha host.rootdir[0] = 0; } #elif (XASH_SDL == 2) && !XASH_NSWITCH // GetBasePath not impl'd in switch-sdl2 - char *szBasePath; - - if( !( szBasePath = SDL_GetBasePath() ) ) + char *szBasePath = SDL_GetBasePath(); + if( szBasePath ) + { + Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir )); + SDL_free( szBasePath ); + } + else + { +#if XASH_POSIX || XASH_WIN32 + if( !getcwd( host.rootdir, sizeof( host.rootdir ))) + Sys_Error( "couldn't determine current directory: %s, getcwd: %s", SDL_GetError(), strerror( errno )); +#else Sys_Error( "couldn't determine current directory: %s", SDL_GetError() ); - Q_strncpy( host.rootdir, szBasePath, sizeof( host.rootdir )); - SDL_free( szBasePath ); +#endif + } #else if( !getcwd( host.rootdir, sizeof( host.rootdir ))) {