From d206b7b1af231632341f39bca0bea4261b645a05 Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Sun, 30 Nov 2025 14:47:03 +0100 Subject: [PATCH] path fix --- src/main.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index aaf215e..2d2e00f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "audio/Audio.h" #include "audio/SoundEffect.h" @@ -681,6 +682,25 @@ int main(int, char **) } SDL_SetRenderVSync(renderer, 1); + // Ensure our working directory matches the executable location so + // relative asset paths (assets/, FreeSans.ttf, etc.) resolve even + // when launching from a macOS .app bundle via Finder. + if (char* basePathRaw = SDL_GetBasePath()) { + std::filesystem::path exeDir(basePathRaw); + SDL_free(basePathRaw); + std::error_code ec; + std::filesystem::current_path(exeDir, ec); + if (ec) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Failed to set working directory to %s: %s", + exeDir.string().c_str(), ec.message().c_str()); + } + } else { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "SDL_GetBasePath() failed; asset lookups rely on current directory: %s", + SDL_GetError()); + } + FontAtlas font; font.init("FreeSans.ttf", 24);