path fix
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@ -14,6 +14,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include "audio/Audio.h"
|
#include "audio/Audio.h"
|
||||||
#include "audio/SoundEffect.h"
|
#include "audio/SoundEffect.h"
|
||||||
@ -681,6 +682,25 @@ int main(int, char **)
|
|||||||
}
|
}
|
||||||
SDL_SetRenderVSync(renderer, 1);
|
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;
|
FontAtlas font;
|
||||||
font.init("FreeSans.ttf", 24);
|
font.init("FreeSans.ttf", 24);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user