Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Windows UI tests get their own settings folder (SF_USER_DATA_DIR): SDL_GetPrefPath ignored the isolated APPDATA

islandmed7f3e20868743
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 53cadbc4..310c6b0d 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -19,6 +19,7 @@
#include "app/Theme.h"
#include "app/Ui.h"
#include "app/UiServe.h"
+#include "app/UserData.h"
#include <IconsLucide.h>
@@ -214,12 +215,11 @@ bool App::init(const AppOptions& options) {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- iniPath_ = std::string(pref) + "imgui.ini";
+ if (const std::string pref = userDataDir(); !pref.empty()) {
+ iniPath_ = pref + "imgui.ini";
io.IniFilename = iniPath_.c_str();
- aiSettingsPath_ = std::string(pref) + "ai.json";
+ aiSettingsPath_ = pref + "ai.json";
aiSettings_ = ai::AiSettings::load(aiSettingsPath_);
- SDL_free(pref);
} else {
io.IniFilename = nullptr;
}
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index b9d8e2cc..290016ef 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -16,6 +16,7 @@
#include "app/Palettes.h"
#include "app/Ui.h"
#include "app/I18n.h"
+#include "app/UserData.h"
#include "core/LegacyNames.h"
#include "core/Bake.h"
#include "core/ListSort.h"
@@ -330,10 +331,7 @@ constexpr Gesture kBlenderGestures[] = {
void App::initUiConfig(bool deterministic) {
uiConfigDeterministic_ = deterministic;
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- configDir_ = pref;
- SDL_free(pref);
- }
+ configDir_ = userDataDir();
layout_ = standardLayout(uiPrefs_.shellLayout);
if (deterministic) return; // tests, renders and recordings always use the standard layout
std::string err;
@@ -795,11 +793,7 @@ void App::saveRecentActions() {
namespace {
std::string windowStatePath() {
- std::string dir;
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- dir = pref;
- SDL_free(pref);
- }
+ const std::string dir = userDataDir();
return dir.empty() ? std::string() : dir + "window.json";
}
} // namespace
diff --git a/src/app/CrashLog.cpp b/src/app/CrashLog.cpp
index 4a4fcbb7..8d2f1cc2 100644
--- a/src/app/CrashLog.cpp
+++ b/src/app/CrashLog.cpp
@@ -1,6 +1,7 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
#include "app/CrashLog.h"
+#include "app/UserData.h"
#include <SDL3/SDL.h>
@@ -213,10 +214,7 @@ void start(const std::string& folder) {
g_lastLogged.clear();
std::string dir = folder;
if (dir.empty()) {
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- dir = pref;
- SDL_free(pref);
- }
+ dir = userDataDir();
}
if (dir.empty()) return;
if (dir.back() != '/' && dir.back() != '\\') dir += '/';
diff --git a/src/app/PanelPerformanceProfile.cpp b/src/app/PanelPerformanceProfile.cpp
index 8f852219..957169a2 100644
--- a/src/app/PanelPerformanceProfile.cpp
+++ b/src/app/PanelPerformanceProfile.cpp
@@ -15,6 +15,7 @@
#include "app/Calibration.h"
#include "app/CrashLog.h"
#include "app/Ui.h"
+#include "app/UserData.h"
#include "core/FrameGovernor.h"
#include "core/HardwareProfile.h"
@@ -561,10 +562,7 @@ void App::togglePerfTrace() {
if (const size_t slash = folder.find_last_of("/\\"); slash != std::string::npos) folder.resize(slash + 1);
else folder.clear();
if (folder.empty()) {
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- folder = pref;
- SDL_free(pref);
- }
+ folder = userDataDir();
}
HardwareInfo hw;
if (hwProfile_) hw = hwProfile_->profile.hardware;
diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cpp
index ab598e9a..3a0a8b7b 100644
--- a/src/app/PanelProject.cpp
+++ b/src/app/PanelProject.cpp
@@ -14,6 +14,7 @@
#include "core/SplatCapture.h"
#include "app/Ui.h"
#include "app/I18n.h"
+#include "app/UserData.h"
#include "ai/Http.h"
@@ -86,10 +87,7 @@ bool App::interactive() const { return options_.renderPath.empty() && options_.r
void App::initProject() {
if (!interactive()) return;
- if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
- prefDir_ = pref;
- SDL_free(pref);
- }
+ prefDir_ = userDataDir();
if (prefDir_.empty()) return;
std::ifstream f(fsPath(prefDir_ + "project.json"), std::ios::binary);
Json prefs;
diff --git a/src/app/UserData.h b/src/app/UserData.h
new file mode 100644
index 00000000..b150825d
--- /dev/null
+++ b/src/app/UserData.h
@@ -0,0 +1,37 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+#include <SDL3/SDL.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <filesystem>
+#include <string>
+
+namespace sf {
+
+// The user data folder (settings, the log, imgui.ini), with its trailing separator; "" when there is none. It is
+// SDL_GetPrefPath's, unless SF_USER_DATA_DIR names another: isolateSettings (main.cpp) sets it for UI tests, renders
+// and agent runs. On Windows SDL asks the shell for %APPDATA% and ignores the variable isolateSettings set, so every
+// Windows UI test shared the runner's real settings and read the ones an earlier test left (0.11.2: support_card
+// found another test's "supporter").
+inline std::string userDataDir() {
+ if (const char* over = std::getenv("SF_USER_DATA_DIR"); over && *over) {
+ const std::filesystem::path dir = std::filesystem::path(std::u8string(over, over + std::strlen(over))) /
+ "SculptForge" / "SculptForge";
+ std::error_code ec;
+ std::filesystem::create_directories(dir, ec);
+ if (ec) return std::string();
+ const std::u8string s = (dir / "").u8string(); // (the trailing separator, as SDL_GetPrefPath has it)
+ return std::string(s.begin(), s.end());
+ }
+ std::string dir;
+ if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
+ dir = pref;
+ SDL_free(pref);
+ }
+ return dir;
+}
+
+} // namespace sf
diff --git a/src/app/main.cpp b/src/app/main.cpp
index d12b6030..6f45a1c6 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -107,6 +107,7 @@ void isolateSettings() {
const std::string d = dir.string();
#if defined(_WIN32)
_putenv_s("APPDATA", d.c_str());
+ _putenv_s("SF_USER_DATA_DIR", d.c_str()); // (SDL_GetPrefPath ignores APPDATA: app/UserData.h)
#else
setenv("XDG_DATA_HOME", d.c_str(), 1);
setenv("XDG_CONFIG_HOME", d.c_str(), 1);