This commit is contained in:
2025-11-30 14:47:03 +01:00
parent 69b3a60564
commit d206b7b1af

View File

@ -14,6 +14,7 @@
#include <cmath>
#include <cstdlib>
#include <memory>
#include <filesystem>
#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);