diff --git a/src/libcore/fresolver.cpp b/src/libcore/fresolver.cpp index 1f1fbed4..13bfb197 100644 --- a/src/libcore/fresolver.cpp +++ b/src/libcore/fresolver.cpp @@ -1,11 +1,20 @@ #include #include -#if defined(__WINDOWS__) +#if defined(__LINUX__) +# if !defined(_GNU_SOURCE) +# define _GNU_SOURCE +# endif +# include +#elif defined(__OSX__) +# include +#elif defined(__WINDOWS__) # include # include #endif + + MTS_NAMESPACE_BEGIN #if defined(__WINDOWS__) @@ -16,8 +25,6 @@ void dummyModuleFunc() {} #endif FileResolver::FileResolver() { - m_paths.push_back(fs::current_path()); - /* Try to detect the base path of the Mitsuba installation */ fs::path basePath; #if defined(__LINUX__) @@ -45,6 +52,8 @@ FileResolver::FileResolver() { } } MTS_AUTORELEASE_END() + if (basePath.empty()) + Log(EError, "Could not detect the executable path!"); #elif defined(__WINDOWS__) std::vector lpFilename(MAX_PATH); @@ -67,17 +76,13 @@ FileResolver::FileResolver() { } // There is an error if and only if the function returns 0 - if (nSize != 0) { - fs::path path(lpFilename); - if (boost::to_lower_copy(path.filename().string()).find("python") == std::string::npos) - prependPath(path.parent_path()); - } else { - const std::string msg(lastErrorText()); - Log(EError, "Could not detect the executable path! (%s)", msg.c_str()); - } + if (nSize != 0) + basePath = fs::path(lpFilename); + else + Log(EError, "Could not detect the executable path! (%s)", lastErrorText().c_str()); #endif - Thread::getThread()->getFileResolver()->prependPath(basePath); - + m_paths.push_back(fs::canonical(basePath)); + m_paths.push_back(fs::current_path()); } FileResolver *FileResolver::clone() const { diff --git a/src/libpython/core.cpp b/src/libpython/core.cpp index ba2715b9..48d8b472 100644 --- a/src/libpython/core.cpp +++ b/src/libpython/core.cpp @@ -21,17 +21,6 @@ #include #include -#if defined(__LINUX__) -# if !defined(_GNU_SOURCE) -# define _GNU_SOURCE -# endif -# include -#elif defined(__OSX__) -# include -#elif defined(__WINDOWS__) -# include -#endif - using namespace mitsuba; void initializeFramework() { @@ -48,31 +37,6 @@ void initializeFramework() { Scheduler::staticInitialization(); SHVector::staticInitialization(); SceneHandler::staticInitialization(); - - - #if defined(__LINUX__) - #elif defined(__OSX__) - #elif defined(__WINDOWS__) - HMODULE hm; - std::vector lpFilename(MAX_PATH); - if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | - GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCSTR) &initializeFramework, &hm)) { - std::vector lpFilename(MAX_PATH); - - // Try to get the path with the default MAX_PATH length (260 chars) - DWORD nSize = GetModuleFileNameW(hm, &lpFilename[0], MAX_PATH); - - // Adjust the buffer size in case if was too short - while (nSize == lpFilename.size()) { - lpFilename.resize(nSize * 2); - nSize = GetModuleFileNameW(hm, &lpFilename[0], nSize); - } - - if (nSize) - basePath = fs::path(lpFilename).parent_path().parent_path().parent_path(); - } - #endif - } void shutdownFramework() {