Skip to content

Commit

Permalink
Fixed chip8 logo rom not loading on startup on macos/linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeGaL0DoN committed Sep 26, 2024
1 parent d7eddf6 commit 33164e3
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,34 @@ inline std::wstring ToUTF16(const std::string& utf8Str)
MultiByteToWideChar(CP_UTF8, 0, utf8Str.c_str(), utf8Str.length(), result.data(), size);
return result;
}

#elif defined(__linux__) || defined(__unix__)
#include <unistd.h>
#elif defined(__APPLE__)
#include <unistd.h>
#include <libproc.h>
#endif

inline std::filesystem::path getExecutablePath()
{
#ifdef _WIN32
wchar_t pathBuf[MAX_PATH];
GetModuleFileNameW(NULL, pathBuf, MAX_PATH);
#else
char pathBuf[4096];
#ifdef __APPLE__
pid_t pid = getpid();
proc_pidpath(pid, pathBuf, sizeof(pathBuf));
#elif defined(__linux__) || defined(__unix__)
ssize_t count = readlink("/proc/self/exe", pathBuf, sizeof(pathBuf));
if (count != -1) pathBuf[count] = '\0';
#endif
#endif

const std::filesystem::path path{ pathBuf };
return path.parent_path();
}

void drop_callback(GLFWwindow* _window, int count, const char** paths)
{
(void)_window;
Expand Down Expand Up @@ -622,7 +648,7 @@ int main()
setBuffers();

std::thread initThread{ ChipCore::initAudio };
loadROM("ROMs/chipLogo.ch8");
loadROM(getExecutablePath() / "ROMs" / "chipLogo.ch8");

double lastTime = glfwGetTime();
double executeTimer{};
Expand Down

0 comments on commit 33164e3

Please sign in to comment.