forge
Explore
Log in

Don't you dare go Hollow

Avoid panics on more wrong VBlank events

Browse files at this commit

6b6a84e55be388589e49fc9ddd8502dd2da7aca9Ivan MolodetskikhParent: 7d5785e
src/backend/tty.rsmodified+18 -17
@@ -1153,15 +1153,24 @@ impl Tty {
1153 return;1153 return;
1154 };1154 };
1155 1155
1156- // This happened for someone reconnecting 2 monitors with a KVM switch:1156+ let redraw_needed = match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {
1157- // https://github.com/YaLTeR/niri/issues/5561157+ RedrawState::WaitingForVBlank { redraw_needed } => redraw_needed,
1158- //1158+ state @ (RedrawState::Idle
1159- // Maybe the vblank didn't get cancelled or got reordered weirdly? Either way, we can avoid1159+ | RedrawState::Queued
1160- // crashing here.1160+ | RedrawState::WaitingForEstimatedVBlank(_)
1161- if matches!(output_state.redraw_state, RedrawState::Idle) {1161+ | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => {
1162- error!("got vblank for an idle output {name}");1162+ // This is an error!() because it shouldn't happen, but on some systems it somehow
1163- return;1163+ // does. Kernel sending rogue vblank events?
1164- }1164+ //
1165+ // https://github.com/YaLTeR/niri/issues/556
1166+ // https://github.com/YaLTeR/niri/issues/615
1167+ error!(
1168+ "unexpected redraw state for output {name} (should be WaitingForVBlank); \
1169+ can happen when resuming from sleep or powering on monitors: {state:?}"
1170+ );
1171+ true
1172+ }
1173+ };
1165 1174
1166 // Mark the last frame as submitted.1175 // Mark the last frame as submitted.
1167 match surface.compositor.frame_submitted() {1176 match surface.compositor.frame_submitted() {
@@ -1209,14 +1218,6 @@ impl Tty {
1209 1218
1210 output_state.frame_clock.presented(presentation_time);1219 output_state.frame_clock.presented(presentation_time);
1211 1220
1212- let redraw_needed = match mem::replace(&mut output_state.redraw_state, RedrawState::Idle) {
1213- RedrawState::Idle => unreachable!(),
1214- RedrawState::Queued => unreachable!(),
1215- RedrawState::WaitingForVBlank { redraw_needed } => redraw_needed,
1216- RedrawState::WaitingForEstimatedVBlank(_) => unreachable!(),
1217- RedrawState::WaitingForEstimatedVBlankAndQueued(_) => unreachable!(),
1218- };
1219-
1220 if redraw_needed || output_state.unfinished_animations_remain {1221 if redraw_needed || output_state.unfinished_animations_remain {
1221 let vblank_frame = tracy_client::Client::running()1222 let vblank_frame = tracy_client::Client::running()
1222 .unwrap()1223 .unwrap()
src/niri.rsmodified+1 -1
@@ -344,7 +344,7 @@ pub struct OutputState {
344 pub debug_damage_tracker: OutputDamageTracker,344 pub debug_damage_tracker: OutputDamageTracker,
345 }345 }
346 346
347-#[derive(Default)]347+#[derive(Debug, Default)]
348 pub enum RedrawState {348 pub enum RedrawState {
349 /// The compositor is idle.349 /// The compositor is idle.
350 #[default]350 #[default]