Skip to content

Commit

Permalink
add temp dirs to the search path
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Dec 20, 2024
1 parent d0ae0f3 commit e558bd3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions loader/src/platform/windows/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ using namespace geode::prelude;

static bool g_lastLaunchCrashed = false;
static bool g_symbolsInitialized = false;
static std::string g_unzippedSearchPaths;

static std::string getDateString(bool filesafe) {
auto const now = std::time(nullptr);
Expand Down Expand Up @@ -478,6 +479,15 @@ static void handleException(LPEXCEPTION_POINTERS info) {
if (!g_symbolsInitialized) {
log::warn("Failed to initialize debug symbols: Error {}", GetLastError());
}
else {
// set the search path to include the mods' temp directories
if (std::array<char, 4096> searchPathBuffer;
SymGetSearchPath(static_cast<HMODULE>(GetCurrentProcess()), searchPathBuffer.data(), searchPathBuffer.size())) {
std::string searchPath(searchPathBuffer.data());
searchPath += ";" + g_unzippedSearchPaths;
SymSetSearchPath(static_cast<HMODULE>(GetCurrentProcess()), searchPath.c_str());
}
}

// in some cases, we can be pretty certain that the first mod found while unwinding
// is the one that caused the crash, so using `suspectedFaultyMod` is safe and correct.
Expand Down Expand Up @@ -521,6 +531,11 @@ static LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS info) {
bool crashlog::setupPlatformHandler() {
SetUnhandledExceptionFilter(exceptionHandler);

g_unzippedSearchPaths.clear();
for (auto& mod : Loader::get()->getAllMods()) {
g_unzippedSearchPaths += mod->getTempDir().string() + ";";
}

auto lastCrashedFile = crashlog::getCrashLogDirectory() / "last-crashed";
if (std::filesystem::exists(lastCrashedFile)) {
g_lastLaunchCrashed = true;
Expand Down

0 comments on commit e558bd3

Please sign in to comment.