mirror of
https://github.com/edera-dev/sprout.git
synced 2025-12-19 13:50:16 +00:00
fix(timer): add check for zero frequency
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use crate::context::SproutContext;
|
use crate::context::SproutContext;
|
||||||
use crate::utils::framebuffer::Framebuffer;
|
use crate::utils::framebuffer::Framebuffer;
|
||||||
use crate::utils::read_file_contents;
|
use crate::utils::read_file_contents;
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result, bail};
|
||||||
use image::imageops::{FilterType, resize};
|
use image::imageops::{FilterType, resize};
|
||||||
use image::math::Rect;
|
use image::math::Rect;
|
||||||
use image::{DynamicImage, ImageBuffer, ImageFormat, ImageReader, Rgba};
|
use image::{DynamicImage, ImageBuffer, ImageFormat, ImageReader, Rgba};
|
||||||
@@ -118,6 +118,11 @@ fn draw(image: DynamicImage) -> Result<()> {
|
|||||||
// Fit the image to the display frame.
|
// Fit the image to the display frame.
|
||||||
let fit = fit_to_frame(&image, 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.
|
// Resize the image to fit the display frame.
|
||||||
let image = resize_to_fit(&image, fit);
|
let image = resize_to_fit(&image, fit);
|
||||||
|
|
||||||
|
|||||||
@@ -53,9 +53,14 @@ fn arch_ticks() -> u64 {
|
|||||||
/// Acquire the tick frequency reported by the platform.
|
/// Acquire the tick frequency reported by the platform.
|
||||||
fn arch_frequency() -> TickFrequency {
|
fn arch_frequency() -> TickFrequency {
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
return aarch64::frequency();
|
let frequency = aarch64::frequency();
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[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.
|
/// Platform timer that allows measurement of the elapsed time.
|
||||||
|
|||||||
@@ -62,9 +62,5 @@ fn measure_frequency() -> u64 {
|
|||||||
/// On x86_64, this is slightly expensive, so it should be done once.
|
/// On x86_64, this is slightly expensive, so it should be done once.
|
||||||
pub fn frequency() -> TickFrequency {
|
pub fn frequency() -> TickFrequency {
|
||||||
let frequency = measure_frequency();
|
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)
|
TickFrequency::Measured(frequency, MEASURE_FREQUENCY_DURATION)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user