mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
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
This commit is contained in:
@@ -565,6 +565,7 @@ impl Context {
|
|||||||
Stroke::new(1.0, Color32::YELLOW.additive().linear_multiply(0.05)),
|
Stroke::new(1.0, Color32::YELLOW.additive().linear_multiply(0.05)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
let mut show_blocking_widget = None;
|
||||||
|
|
||||||
self.write(|ctx| {
|
self.write(|ctx| {
|
||||||
ctx.layer_rects_this_frame
|
ctx.layer_rects_this_frame
|
||||||
@@ -585,16 +586,9 @@ impl Context {
|
|||||||
// so we aren't hovered.
|
// so we aren't hovered.
|
||||||
|
|
||||||
if ctx.memory.options.style.debug.show_blocking_widget {
|
if ctx.memory.options.style.debug.show_blocking_widget {
|
||||||
Self::layer_painter(self, LayerId::debug()).debug_rect(
|
// Store the rects to use them outside the write() call to
|
||||||
interact_rect,
|
// avoid deadlock
|
||||||
Color32::GREEN,
|
show_blocking_widget = Some((interact_rect, prev_rect));
|
||||||
"Covered",
|
|
||||||
);
|
|
||||||
Self::layer_painter(self, LayerId::debug()).debug_rect(
|
|
||||||
prev_rect,
|
|
||||||
Color32::LIGHT_BLUE,
|
|
||||||
"On top",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hovered = false;
|
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)
|
self.interact_with_hovered(layer_id, id, rect, sense, enabled, hovered)
|
||||||
|
|||||||
Reference in New Issue
Block a user