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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
SG4: a part whose entity had already gone is an error naming it and the frame
shinyobjectz4bdc4749e48e
diff --git a/engine/render/src/engine.rs b/engine/render/src/engine.rsindex 23e87099..f36337d8 100644--- a/engine/render/src/engine.rs+++ b/engine/render/src/engine.rs@@ -321,9 +321,9 @@ impl Engine {}/// A live scene's rows dropped, by kind and id: their entities go (and the meshes and surfaces only they held).- pub fn remove_rows(&mut self, rows: &[(String, String)]) {+ pub fn remove_rows(&mut self, rows: &[(String, String)]) -> Result<(), String> {rows.iter().for_each(|r| drop(self.kept.remove(r)));- remove_rows_from(self.app.world_mut(), rows);+ remove_rows_from(self.app.world_mut(), rows)}/// The registered Bevy plugins' frame clock: the frames before f stepped through (one update each, their readbacksdiff --git a/engine/render/src/engine/spawn.rs b/engine/render/src/engine/spawn.rsindex 476e5aae..c355ec10 100644--- a/engine/render/src/engine/spawn.rs+++ b/engine/render/src/engine/spawn.rs@@ -143,7 +143,7 @@ pub fn screen_images(world: &World) -> Vec<(String, Handle<Image>, u32, u32)> {/// A live scene's rows dropped from a World, by kind and id (Engine::remove_rows, or a plain App's): their entities go,/// and the rows after them take their places.-pub fn remove_rows_from(world: &mut World, rows: &[(String, String)]) {+pub fn remove_rows_from(world: &mut World, rows: &[(String, String)]) -> Result<(), String> {// each dropped row's place as the rows stand now, then the places dropped from the last back, so a drop never// moves a place still to come. Before, each place was dropped as it was found: a second row dropped in the// same call took the place it had before the first moved it up, dropping its neighbour's values instead, and@@ -151,10 +151,14 @@ pub fn remove_rows_from(world: &mut World, rows: &[(String, String)]) {// to make their meshes, dropped together on its third frame: its body gone and other parts drawn huge,// 2026-10-20)let mut places = Vec::new();+ let mut gone = Vec::new();for (kind, id) in rows {let Some(e) = store::find(world, kind, id) else { continue };let Some(r) = world.resource::<FrameRows>().ix.get(&e).copied() else { continue };- store::despawn(world, e);+ // its place drops either way (the store drops the row); a row whose entity had already gone is an error (SG4)+ if let Err(m) = store::despawn(world, e) {+ gone.push(m);+ }places.push(r);}let any = !places.is_empty();@@ -166,6 +170,7 @@ pub fn remove_rows_from(world: &mut World, rows: &[(String, String)]) {let ix: bevy::ecs::entity::EntityHashMap<usize> = store::rows(world).iter().enumerate().map(|(r, &e)| (e, r)).collect();world.resource_mut::<FrameRows>().ix = ix;}+ if gone.is_empty() { Ok(()) } else { Err(gone.join("; ")) }}/// Where a plain App's 3D camera draws when its camera row arrives through apply_rows (an Engine's draws into its frame).diff --git a/engine/web/src/lib.rs b/engine/web/src/lib.rsindex 9274b277..4f499730 100644--- a/engine/web/src/lib.rs+++ b/engine/web/src/lib.rs@@ -78,7 +78,7 @@ impl Raea {let e = self.engine.as_mut().expect("opened");let (rows, gone) = self.ls.frame(shot);if !gone.is_empty() {- e.remove_rows(&gone);+ e.remove_rows(&gone).map_err(|e| JsError::new(&e))?;}if !rows.is_empty() {e.set_rows(&rows).map_err(|e| JsError::new(&e))?;diff --git a/runtime/export/src/bevy_frame.rs b/runtime/export/src/bevy_frame.rsindex 8afe9751..c71d601e 100644--- a/runtime/export/src/bevy_frame.rs+++ b/runtime/export/src/bevy_frame.rs@@ -35,6 +35,11 @@ pub(crate) fn snapshot_bevy(world: &mut World, page: &mut raea_runtime_page::BevOk(Frame { screens, mix: cx.mix, page: stored, sounds: cx.sounds.clone(), scene: cx.scene.clone(), clear: cx.clear.clone(), same: false })}+/// A live scene's error with the frame it came on (docs/stage-guards.feature SG4), unless it names one already.+fn on_frame(r: Result<(), String>, now: i64) -> Result<(), String> {+ r.map_err(|m| if m.starts_with("frame ") { m } else { format!("frame {now}: {m}") })+}+/// One frame on the bevy_ui page over its 3D drawn live (cx.scene3d, the engine render_fed opens: handles resolved from/// the edit's folder, world calls answered): each <Screen>'s picture handed to the engine, the 3D drawn as the fed render/// draws it and its target read back, and the page laid over it. Straight RGBA, opaque (with --alpha, transparent where nothing is drawn: #114).@@ -58,7 +63,7 @@ pub(crate) fn bevy_over_3d(world: &mut World, page: &mut raea_runtime_page::Bevy// a game's: this frame's 3D, just stepped, set on its engine (opened at the first frame with any), as the Blitz// fed render's snapshot_retained doesif let Some(ls) = cx.live3d.as_mut() {- live_scene(world, ls, &mut cx.scene3d, (page.w, page.h), fps, cx.dir)?;+ on_frame(live_scene(world, ls, &mut cx.scene3d, (page.w, page.h), fps, cx.dir), cx.now)?;}let (px, pics) = bevy_page_frame(world, page, cx)?;// with --alpha (#114) what the page and its 3D leave empty stays transparent, as a page alone does; else over black@@ -153,8 +158,7 @@ pub(crate) fn bevy_fed_buffer(w: u32, h: u32) -> R<wgpu::Buffer> {}/// One frame of a fed render on the bevy_ui page: the page laid over the frame's 3D (drawn live, bevy_over_3d), or-/// the page alone, written into the frame buffer raea-render takes; the frame's sound, mix and screens as the Blitz fed frame-/// carries them.+/// the page alone, written into the frame buffer raea-render takes; the frame's sound, mix and screens as Blitz's fed frame carries them.pub(crate) fn bevy_fed(world: &mut World, page: &mut raea_runtime_page::BevyPage, cx: &mut Ctx, buf: &wgpu::Buffer, fps: f64) -> R<Frame> {let g = raea_runtime_view::gpuview::paint_device().ok_or("a fed render needs the shared GPU device")?;// on the GPU (B1d), unless the frames are dumped as files or RAEA_FEED_CPU=1 asks for the readback it replaced@@ -178,7 +182,7 @@ thread_local! {/// GPU too; read back only on a frame where a screen has no image in the 3D yet (its first).pub(crate) fn bevy_fed_gpu(world: &mut World, page: &mut raea_runtime_page::BevyPage, cx: &mut Ctx, buf: &wgpu::Buffer, fps: f64, device: &wgpu::Device, queue: &wgpu::Queue) -> R<()> {if let Some(ls) = cx.live3d.as_mut() {- live_scene(world, ls, &mut cx.scene3d, (page.w, page.h), fps, cx.dir)?;+ on_frame(live_scene(world, ls, &mut cx.scene3d, (page.w, page.h), fps, cx.dir), cx.now)?;}bevy_page_sync(world, page, cx)?;page.draw();diff --git a/runtime/export/src/fed.rs b/runtime/export/src/fed.rsindex 0c372a46..01c29ffc 100644--- a/runtime/export/src/fed.rs+++ b/runtime/export/src/fed.rs@@ -161,7 +161,7 @@ pub fn live_scene(world: &mut World, ls: &mut LiveScene, engine: &mut Option<raelet clear = scene_clear(world);let (rows, gone) = ls.frame(Shot { scene: &scene, clear: clear.as_deref() });if !gone.is_empty() {- e.remove_rows(&gone);+ e.remove_rows(&gone)?;}if !rows.is_empty() {e.set_rows(&rows)?;diff --git a/runtime/react/src/scene/plugin.rs b/runtime/react/src/scene/plugin.rsindex f8e0cf92..43ff2fc3 100644--- a/runtime/react/src/scene/plugin.rs+++ b/runtime/react/src/scene/plugin.rs@@ -82,7 +82,7 @@ pub(crate) fn scene_rows_into(world: &mut World, s: &mut SceneRows) -> R<()> {(raea_render::inserted_of(&p), Vec::new())};if !gone.is_empty() {- raea_render::engine::remove_rows_from(world, &gone);+ raea_render::engine::remove_rows_from(world, &gone)?;}if !rows.is_empty() {// a glTF model spawned here loads over the frames after, as any Bevy App's doesdiff --git a/systems/frame/src/store.rs b/systems/frame/src/store.rsindex bbc46dcb..8ed12c95 100644--- a/systems/frame/src/store.rs+++ b/systems/frame/src/store.rs@@ -86,16 +86,35 @@ pub fn spawn(world: &mut World, t: &Tup) -> Entity {e}-/// Remove a row (the entity goes with it, and whatever else was attached to it).-pub fn despawn(world: &mut World, e: Entity) {- if let Some(k) = world.get::<RowKey>(e).cloned() {- let s = schema(world);- s.order.retain(|x| *x != e);- if let Some(m) = s.by.get_mut(&k.kind) {- m.remove(&k.id);+/// Remove a row (the entity goes with it, and whatever else was attached to it). A row whose entity is already gone+/// (despawned with another row it hung from) is dropped from the store all the same, and named in the error: Bevy's+/// own "Could not despawn entity" was a log line nobody read while the row's part was drawn wrong (docs/stage-guards.feature SG4).+pub fn despawn(world: &mut World, e: Entity) -> Result<(), String> {+ let key = world.get::<RowKey>(e).cloned();+ let s = schema(world);+ s.order.retain(|x| *x != e);+ let named = match &key {+ Some(k) => {+ if let Some(m) = s.by.get_mut(&k.kind) {+ m.remove(&k.id);+ }+ None}- }- world.despawn(e);+ // gone: its kind and id from the store's index, which still holds it+ None => {+ let found = s.by.iter().find_map(|(kind, m)| m.iter().find(|(_, x)| **x == e).map(|(id, _)| (kind.clone(), id.clone())));+ if let Some((kind, id)) = &found {+ if let Some(m) = s.by.get_mut(kind) {+ m.remove(id);+ }+ }+ found+ }+ };+ world.try_despawn(e).map_err(|err| match named {+ Some((kind, id)) => format!("Could not despawn entity: the {kind} part '{id}' had already gone, despawned with another part it hung from ({err})"),+ None => format!("Could not despawn entity: {err}"),+ })}/// Remove every row.@@ -252,7 +271,13 @@ mod tests {assert_eq!(get(&s.world, e, "y"), Some(V::N(5.0)));assert_eq!(s.gather().to_tups()[1].vals["y"], V::N(5.0));let a = find(&s.world, "title", "a").unwrap();- despawn(&mut s.world, a);+ despawn(&mut s.world, a).unwrap();assert_eq!(s.tups().len(), 2);+ // a row whose entity went with another (SG4) is an error naming it, and leaves the store+ let b = find(&s.world, "title", "b").unwrap();+ s.world.despawn(b);+ let err = despawn(&mut s.world, b).unwrap_err();+ assert!(err.contains("the title part 'b' had already gone"), "{err}");+ assert_eq!(find(&s.world, "title", "b"), None);}}