fix(timer): add check for zero frequency

This commit is contained in:
2025-11-01 19:18:04 -04:00
parent 3b32f6c3ce
commit 757d10ec65
3 changed files with 13 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
use crate::context::SproutContext;
use crate::utils::framebuffer::Framebuffer;
use crate::utils::read_file_contents;
use anyhow::{Context, Result};
use anyhow::{Context, Result, bail};
use image::imageops::{FilterType, resize};
use image::math::Rect;
use image::{DynamicImage, ImageBuffer, ImageFormat, ImageReader, Rgba};
@@ -118,6 +118,11 @@ fn draw(image: DynamicImage) -> Result<()> {
// Fit the image to the display frame.
let fit = fit_to_frame(&image, display_frame);
// If the image is zero-sized, then we should bail with an error.
if fit.width == 0 || fit.height == 0 {
bail!("calculated frame size is zero");
}
// Resize the image to fit the display frame.
let image = resize_to_fit(&image, fit);

View File

@@ -53,9 +53,14 @@ fn arch_ticks() -> u64 {
/// Acquire the tick frequency reported by the platform.
fn arch_frequency() -> TickFrequency {
#[cfg(target_arch = "aarch64")]
return aarch64::frequency();
let frequency = aarch64::frequency();
#[cfg(target_arch = "x86_64")]
return x86_64::frequency();
let frequency = x86_64::frequency();
// If the frequency is 0, then something went very wrong and we should panic.
if frequency.ticks() == 0 {
panic!("timer frequency is zero");
}
frequency
}
/// Platform timer that allows measurement of the elapsed time.

View File

@@ -62,9 +62,5 @@ fn measure_frequency() -> u64 {
/// On x86_64, this is slightly expensive, so it should be done once.
pub fn frequency() -> TickFrequency {
let frequency = measure_frequency();
// If the frequency is 0, then something went very wrong and we should panic.
if frequency == 0 {
panic!("unable to measure frequency");
}
TickFrequency::Measured(frequency, MEASURE_FREQUENCY_DURATION)
}