Skip to content

Commit

Permalink
Fix deadlock when using show_blocking_widget (emilk#2753)
Browse files Browse the repository at this point in the history
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 emilk#2752
  • Loading branch information
YgorSouza authored and mikedilger committed Mar 7, 2023
1 parent a4f41bb commit 8eafebd
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 8eafebd

Please sign in to comment.