Skip to content

Commit

Permalink
Fix memory crash on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
dapetcu21 committed Jan 26, 2022
1 parent 1db17ad commit 8b88fc1
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions defoldprojectdir/src/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static int GetExecutablePath(lua_State* L) {

#if defined(DM_PLATFORM_OSX) || defined(DM_PLATFORM_WINDOWS) || defined(DM_PLATFORM_LINUX)

#ifdef _WIN32
static char * dirname(char * path) {
// Mutates path in-place and doesn't do any allocations
static char * portableDirname(char * path) {
size_t i = strlen(path);
do {
i -= 1;
Expand All @@ -86,7 +86,6 @@ static char * dirname(char * path) {
} while (i);
return path;
}
#endif

static bool endsIn(const char * haystack, const char * needle) {
size_t needleLen = strlen(needle);
Expand Down Expand Up @@ -126,7 +125,7 @@ static char * getProjectDir() {
#else
if (endsIn(exePath, FMB_EDITOR_SUFFIX)) {
#endif
char* projPath = (char*)dirname(dirname(dirname(exePath)));
char* projPath = (char*)portableDirname(portableDirname(portableDirname(exePath)));
return projPath;
}
#endif
Expand Down

0 comments on commit 8b88fc1

Please sign in to comment.