Make sure we always track the root viewport (#7450)
Some sanity checks I added while working on another bug
This commit is contained in:
parent
a7ae1012e5
commit
839ee3eaf7
|
|
@ -770,6 +770,7 @@ impl Default for Context {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let ctx_impl = ContextImpl {
|
let ctx_impl = ContextImpl {
|
||||||
embed_viewports: true,
|
embed_viewports: true,
|
||||||
|
viewports: std::iter::once((ViewportId::ROOT, ViewportState::default())).collect(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let ctx = Self(Arc::new(RwLock::new(ctx_impl)));
|
let ctx = Self(Arc::new(RwLock::new(ctx_impl)));
|
||||||
|
|
@ -1617,7 +1618,14 @@ impl Context {
|
||||||
self.read(|ctx| {
|
self.read(|ctx| {
|
||||||
ctx.viewports
|
ctx.viewports
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.map_or(0, |v| v.repaint.cumulative_frame_nr)
|
.map(|v| v.repaint.cumulative_frame_nr)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
panic!("cumulative_frame_nr_for failed to find the viewport {id:?}");
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2516,6 +2524,10 @@ impl ContextImpl {
|
||||||
self.last_viewport = ended_viewport_id;
|
self.last_viewport = ended_viewport_id;
|
||||||
|
|
||||||
self.viewports.retain(|&id, viewport| {
|
self.viewports.retain(|&id, viewport| {
|
||||||
|
if id == ViewportId::ROOT {
|
||||||
|
return true; // never remove the root
|
||||||
|
}
|
||||||
|
|
||||||
let parent = *self.viewport_parents.entry(id).or_default();
|
let parent = *self.viewport_parents.entry(id).or_default();
|
||||||
|
|
||||||
if !all_viewport_ids.contains(&parent) {
|
if !all_viewport_ids.contains(&parent) {
|
||||||
|
|
@ -2586,6 +2598,10 @@ impl ContextImpl {
|
||||||
if is_last {
|
if is_last {
|
||||||
// Remove dead viewports:
|
// Remove dead viewports:
|
||||||
self.viewports.retain(|id, _| all_viewport_ids.contains(id));
|
self.viewports.retain(|id, _| all_viewport_ids.contains(id));
|
||||||
|
debug_assert!(
|
||||||
|
self.viewports.contains_key(&ViewportId::ROOT),
|
||||||
|
"Bug in egui: we removed the root viewport"
|
||||||
|
);
|
||||||
self.viewport_parents
|
self.viewport_parents
|
||||||
.retain(|id, _| all_viewport_ids.contains(id));
|
.retain(|id, _| all_viewport_ids.contains(id));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue