From 2719412f652a584b9b3ad7b3a7b1eec311eb35dc Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 2 Feb 2016 18:00:33 -0800 Subject: [PATCH] Make batch updates and delivery of a new frame into an atomic operation. Before this patch, there was a chance that batch updates could be delivered to the compositor thread (destroying old resources) and then a render operation could be invoked before arrival of the new frame. This would cause the compositor thread to attempt to render frame N with the resources of frame N+1, which would usually crash. Closes #160. --- src/internal_types.rs | 3 +-- src/render_backend.rs | 8 ++------ src/renderer.rs | 6 ++---- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/internal_types.rs b/src/internal_types.rs index 59009142a1..f06c4fe205 100644 --- a/src/internal_types.rs +++ b/src/internal_types.rs @@ -558,9 +558,8 @@ impl RendererFrame { pub enum ResultMsg { UpdateTextureCache(TextureUpdateList), - UpdateBatches(BatchUpdateList), RefreshShader(PathBuf), - NewFrame(RendererFrame, BackendProfileCounters), + NewFrame(RendererFrame, BatchUpdateList, BackendProfileCounters), } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/src/render_backend.rs b/src/render_backend.rs index df5448975b..ef340bf9fa 100644 --- a/src/render_backend.rs +++ b/src/render_backend.rs @@ -294,18 +294,14 @@ impl RenderBackend { self.result_tx.send(ResultMsg::UpdateTextureCache(pending_update)).unwrap(); } - let pending_update = self.frame.pending_updates(); - if pending_update.updates.len() > 0 { - self.result_tx.send(ResultMsg::UpdateBatches(pending_update)).unwrap(); - } - frame } fn publish_frame(&mut self, frame: RendererFrame, profile_counters: &mut BackendProfileCounters) { - let msg = ResultMsg::NewFrame(frame, profile_counters.clone()); + let pending_updates = self.frame.pending_updates(); + let msg = ResultMsg::NewFrame(frame, pending_updates, profile_counters.clone()); self.result_tx.send(msg).unwrap(); profile_counters.reset(); diff --git a/src/renderer.rs b/src/renderer.rs index c26854bf06..50049f5cd6 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -302,11 +302,9 @@ impl Renderer { ResultMsg::UpdateTextureCache(update_list) => { self.pending_texture_updates.push(update_list); } - ResultMsg::UpdateBatches(update_list) => { - self.pending_batch_updates.push(update_list); - } - ResultMsg::NewFrame(frame, profile_counters) => { + ResultMsg::NewFrame(frame, update_list, profile_counters) => { self.backend_profile_counters = profile_counters; + self.pending_batch_updates.push(update_list); self.current_frame = Some(frame); } ResultMsg::RefreshShader(path) => {