debug: Fix crashes and deadlocks

This commit is contained in:
Victoria Brekenfeld 2025-04-24 18:59:26 +02:00 committed by Victoria Brekenfeld
parent 4e6713291d
commit 7c222ae6d1
2 changed files with 18 additions and 9 deletions

View file

@ -219,14 +219,18 @@ impl Timings {
}
pub fn avg_rendertime(&self) -> Duration {
if self.previous_frames.is_empty() {
return Duration::ZERO;
}
self.previous_frames
let Some(sum_rendertime) = self
.previous_frames
.iter()
.map(|f| f.render_time())
.sum::<Duration>()
/ (self.previous_frames.len() as u32)
.try_fold(Duration::ZERO, |acc, x| acc.checked_add(x))
else {
return Duration::ZERO;
};
sum_rendertime
.checked_div(self.previous_frames.len() as u32)
.unwrap_or(Duration::ZERO)
}
pub fn avg_submittime(&self, window: usize) -> Option<Duration> {
@ -269,9 +273,12 @@ impl Timings {
(Some(Frame { render_start, .. }), Some(end_frame)) => {
Time::elapsed(render_start, end_frame.render_start.clone()) + end_frame.frame_time()
}
_ => Duration::ZERO,
_ => {
return 0.0;
}
}
.as_secs_f64();
1.0 / (secs / self.previous_frames.len() as f64)
}

View file

@ -572,15 +572,16 @@ where
CosmicMappedRenderElement<R>: RenderElement<R>,
WorkspaceRenderElement<R>: RenderElement<R>,
{
let shell_guard = shell.read().unwrap();
#[cfg(feature = "debug")]
let mut debug_elements = {
let output_geo = output.geometry();
let shell_guard = shell.read().unwrap();
let seats = shell_guard.seats.iter().cloned().collect::<Vec<_>>();
let debug_active = shell_guard.debug_active;
std::mem::drop(shell_guard);
let scale = output.current_scale().fractional_scale();
if let Some((state, timings)) = _fps {
let debug_active = shell_guard.debug_active;
vec![fps_ui(
_gpu,
debug_active,
@ -601,6 +602,7 @@ where
}
};
let shell_guard = shell.read().unwrap();
let Some((previous_workspace, workspace)) = shell_guard.workspaces.active(output) else {
#[cfg(not(feature = "debug"))]
return Ok(Vec::new());