From 8eafebd9d92539917e4337ca342961f2b862b704 Mon Sep 17 00:00:00 2001 From: YgorSouza <43298013+YgorSouza@users.noreply.github.com> Date: Tue, 28 Feb 2023 20:52:37 +0100 Subject: [PATCH] Fix deadlock when using show_blocking_widget (#2753) Calling the layer painter from inside a write() call causes a deadlock on the Context. This change stores the necessary data (the two overlapping Rects) in the write() call but uses them outside. Closes #2752 --- crates/egui/src/context.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index b7b65fc3122..27c9a6ec0d8 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -565,6 +565,7 @@ impl Context { Stroke::new(1.0, Color32::YELLOW.additive().linear_multiply(0.05)), ); } + let mut show_blocking_widget = None; self.write(|ctx| { ctx.layer_rects_this_frame @@ -585,16 +586,9 @@ impl Context { // so we aren't hovered. if ctx.memory.options.style.debug.show_blocking_widget { - Self::layer_painter(self, LayerId::debug()).debug_rect( - interact_rect, - Color32::GREEN, - "Covered", - ); - Self::layer_painter(self, LayerId::debug()).debug_rect( - prev_rect, - Color32::LIGHT_BLUE, - "On top", - ); + // Store the rects to use them outside the write() call to + // avoid deadlock + show_blocking_widget = Some((interact_rect, prev_rect)); } hovered = false; @@ -605,6 +599,19 @@ impl Context { } } }); + + if let Some((interact_rect, prev_rect)) = show_blocking_widget { + Self::layer_painter(self, LayerId::debug()).debug_rect( + interact_rect, + Color32::GREEN, + "Covered", + ); + Self::layer_painter(self, LayerId::debug()).debug_rect( + prev_rect, + Color32::LIGHT_BLUE, + "On top", + ); + } } self.interact_with_hovered(layer_id, id, rect, sense, enabled, hovered)