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:
YgorSouza 2023-02-28 20:52:37 +01:00 committed by GitHub
parent 7215fdfb7c
commit f85a25307d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 10 deletions

View File

@ -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,6 +586,21 @@ 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 {
// Store the rects to use them outside the write() call to
// avoid deadlock
show_blocking_widget = Some((interact_rect, prev_rect));
}
hovered = false;
break;
}
}
}
}
}
});
if let Some((interact_rect, prev_rect)) = show_blocking_widget {
Self::layer_painter(self, LayerId::debug()).debug_rect( Self::layer_painter(self, LayerId::debug()).debug_rect(
interact_rect, interact_rect,
Color32::GREEN, Color32::GREEN,
@ -596,15 +612,6 @@ impl Context {
"On top", "On top",
); );
} }
hovered = false;
break;
}
}
}
}
}
});
} }
self.interact_with_hovered(layer_id, id, rect, sense, enabled, hovered) self.interact_with_hovered(layer_id, id, rect, sense, enabled, hovered)