Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

raea make: plan.org replaced through one helper; modelbox's forget reads its cache as contact's doesn't (copied code)

shinyobjectz7450537a46bc
diff --git a/apps/make/src/plan.rs b/apps/make/src/plan.rs
index 3046b788..22de4066 100644
--- a/apps/make/src/plan.rs
+++ b/apps/make/src/plan.rs
@@ -82,12 +82,14 @@ pub fn write(root: &Path, brief: &Path, kind: &str, status: &Value) -> Result<(s
let text = std::fs::read_to_string(&file).unwrap_or_default();
let next = update(&text, &title, &rel, kind, status);
if next != text {
- // written beside it, then moved over it: a reader never sees half a plan
- let tmp = file.with_extension("org.tmp");
- let wrote = std::fs::write(&tmp, &next);
- if let Err(e) = wrote.and_then(|()| std::fs::rename(&tmp, &file)) {
- return Err(format!("{}: {e}", file.display()));
- }
+ replace(&file, &next).map_err(|e| format!("{}: {e}", file.display()))?;
}
Ok((file, task_id(&rel)))
}
+
+/// A file's text replaced: written beside it, then moved over it, so a reader never sees half a plan.
+fn replace(file: &Path, text: &str) -> std::io::Result<()> {
+ let tmp = file.with_extension("org.tmp");
+ std::fs::write(&tmp, text)?;
+ std::fs::rename(&tmp, file)
+}
diff --git a/core/modelbox/src/lib.rs b/core/modelbox/src/lib.rs
index 406ec81a..49c39a41 100644
--- a/core/modelbox/src/lib.rs
+++ b/core/modelbox/src/lib.rs
@@ -14,8 +14,8 @@ static CACHE: OnceLock<Mutex<HashMap<String, Result<Arc<Vec<Vec3>>, String>>>> =
/// Lets go of every file's triangles this process read (raea-sys-contact's `forget` calls it with its solids).
pub fn forget() {
- if let Some(c) = CACHE.get() {
- c.lock().unwrap().clear();
+ if let Some(mut files) = CACHE.get().and_then(|c| c.lock().ok()) {
+ files.clear();
}
}