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.

Window state and project.json: temp file, then rename (a quit ending mid-write keeps the last whole copy)

islandmed12ef4bf67f2c
diff --git a/changes/fix-prefs-atomic.md b/changes/fix-prefs-atomic.md
new file mode 100644
index 00000000..29a178ba
--- /dev/null
+++ b/changes/fix-prefs-atomic.md
@@ -0,0 +1,10 @@
+---
+fixed: The window's size and place and project.json (recent files, Discord and autosave settings) are written to a
+ temporary file and then renamed, so a quit that ends mid-write (a stalled disk) keeps the last whole copy.
+testers:
+ - Windows, real hardware: Preferences > Integrations > Show SculptForge on Discord on, sculpt a stroke, close the
+ window. Within 15 s SculptForge.exe is gone from Task Manager and the Discord status is cleared. Start again:
+ the window opens where it was, and Open Recent still lists your files.
+---
+Follow-up to fix/presence-on-exit (merge-0106-4b's review): the exit watchdog's _exit / TerminateProcess could land
+mid-write on a stalled disk. ui.json already used writeJsonAtomic; window.json and project.json now do too.
diff --git a/src/app/Config.cpp b/src/app/Config.cpp
index 2a82922f..973f378a 100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@ -886,8 +886,8 @@ void App::saveWindowState() const {
}
j.set("maximized", maximized);
j.set("fullscreen", fullscreen);
- std::ofstream out(path);
- out << j.dump(true);
+ std::string err; // (temp file, then rename: a quit that ends mid-write leaves the last one whole)
+ if (!writeJsonAtomic(path, j, err)) SDL_Log("%s", err.c_str());
}
std::string App::uiConfigPath() const { return configDir_.empty() ? std::string() : configDir_ + "ui.json"; }
diff --git a/src/app/PanelProject.cpp b/src/app/PanelProject.cpp
index 82b5a7dc..20297aa3 100644
--- a/src/app/PanelProject.cpp
+++ b/src/app/PanelProject.cpp
@@ -219,7 +219,8 @@ void App::saveProjectPrefs() {
prefs.set("new_look_card_done", newLookCardDone_);
prefs.set("quick_tour_done", quickTourDone_);
prefs.set("confirm_subdivide", uiPrefs_.confirmSubdivide);
- std::ofstream(fsPath(prefDir_ + "project.json"), std::ios::binary | std::ios::trunc) << prefs.dump(true);
+ std::string err; // (temp file, then rename: a quit that ends mid-write leaves the last one whole)
+ if (!writeJsonAtomic(prefDir_ + "project.json", prefs, err)) SDL_Log("%s", err.c_str());
}
void App::rememberRecent(const std::string& path) {