Skip to content

Commit 7c222ae

Browse files
committed
debug: Fix crashes and deadlocks
1 parent 4e67132 commit 7c222ae

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/backend/kms/surface/timings.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,18 @@ impl Timings {
219219
}
220220

221221
pub fn avg_rendertime(&self) -> Duration {
222-
if self.previous_frames.is_empty() {
223-
return Duration::ZERO;
224-
}
225-
self.previous_frames
222+
let Some(sum_rendertime) = self
223+
.previous_frames
226224
.iter()
227225
.map(|f| f.render_time())
228-
.sum::<Duration>()
229-
/ (self.previous_frames.len() as u32)
226+
.try_fold(Duration::ZERO, |acc, x| acc.checked_add(x))
227+
else {
228+
return Duration::ZERO;
229+
};
230+
231+
sum_rendertime
232+
.checked_div(self.previous_frames.len() as u32)
233+
.unwrap_or(Duration::ZERO)
230234
}
231235

232236
pub fn avg_submittime(&self, window: usize) -> Option<Duration> {
@@ -269,9 +273,12 @@ impl Timings {
269273
(Some(Frame { render_start, .. }), Some(end_frame)) => {
270274
Time::elapsed(render_start, end_frame.render_start.clone()) + end_frame.frame_time()
271275
}
272-
_ => Duration::ZERO,
276+
_ => {
277+
return 0.0;
278+
}
273279
}
274280
.as_secs_f64();
281+
275282
1.0 / (secs / self.previous_frames.len() as f64)
276283
}
277284

src/backend/render/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,15 +572,16 @@ where
572572
CosmicMappedRenderElement<R>: RenderElement<R>,
573573
WorkspaceRenderElement<R>: RenderElement<R>,
574574
{
575-
let shell_guard = shell.read().unwrap();
576575
#[cfg(feature = "debug")]
577576
let mut debug_elements = {
578577
let output_geo = output.geometry();
578+
let shell_guard = shell.read().unwrap();
579579
let seats = shell_guard.seats.iter().cloned().collect::<Vec<_>>();
580+
let debug_active = shell_guard.debug_active;
581+
std::mem::drop(shell_guard);
580582
let scale = output.current_scale().fractional_scale();
581583

582584
if let Some((state, timings)) = _fps {
583-
let debug_active = shell_guard.debug_active;
584585
vec![fps_ui(
585586
_gpu,
586587
debug_active,
@@ -601,6 +602,7 @@ where
601602
}
602603
};
603604

605+
let shell_guard = shell.read().unwrap();
604606
let Some((previous_workspace, workspace)) = shell_guard.workspaces.active(output) else {
605607
#[cfg(not(feature = "debug"))]
606608
return Ok(Vec::new());

0 commit comments

Comments
 (0)