From 14d2dfdd4c8989dacb77f5598aaf8759225fb8fe Mon Sep 17 00:00:00 2001 From: SoftFever Date: Mon, 15 Jun 2026 14:29:30 +0800 Subject: [PATCH] Fix test errors by guarding against null dereference of wxTheApp in OrcaCloudServiceAgent::compute_fallback_path() and skipping file persistence when no fallback path is available. --- src/slic3r/Utils/OrcaCloudServiceAgent.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/slic3r/Utils/OrcaCloudServiceAgent.cpp b/src/slic3r/Utils/OrcaCloudServiceAgent.cpp index 61eb388b92..215216651e 100644 --- a/src/slic3r/Utils/OrcaCloudServiceAgent.cpp +++ b/src/slic3r/Utils/OrcaCloudServiceAgent.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #if defined(_WIN32) @@ -1416,6 +1417,10 @@ void OrcaCloudServiceAgent::persist_refresh_token(const std::string& token) } compute_fallback_path(); + if (refresh_fallback_path.empty()) { + BOOST_LOG_TRIVIAL(warning) << "OrcaCloudServiceAgent: no refresh-token storage path available; skipping file persistence"; + return; + } wxFileName path(wxString::FromUTF8(refresh_fallback_path.c_str())); path.Normalize(); if (!wxFileName::DirExists(path.GetPath())) { @@ -2219,7 +2224,15 @@ bool OrcaCloudServiceAgent::http_post_auth(const std::string& path, const std::s void OrcaCloudServiceAgent::compute_fallback_path() { - if (!refresh_fallback_path.empty()) return; + if (!refresh_fallback_path.empty()) + return; + // wxStandardPaths::GetUserDataDir() resolves the app data directory via + // wxAppConsoleBase::GetAppName(), which dereferences wxTheApp. In headless + // contexts (CLI, unit tests) there is no wxApp, so guard the call to avoid a + // null dereference. The path can still be provided explicitly through + // set_config_dir(); when it is left empty, file persistence is skipped. + if (wxTheApp == nullptr) + return; wxFileName fallback(wxStandardPaths::Get().GetUserDataDir(), "orca_refresh_token.sec"); fallback.Normalize(); refresh_fallback_path = fallback.GetFullPath().ToStdString();