From b542973e911cdeef397a6d1c440ef248143b2c75 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Sat, 1 Apr 2023 19:56:40 +0100 Subject: [PATCH] Only save cached kttf image when using FileAssetIo --- kayak_font/src/ttf/loader.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kayak_font/src/ttf/loader.rs b/kayak_font/src/ttf/loader.rs index 7eb6d3e..e45706b 100644 --- a/kayak_font/src/ttf/loader.rs +++ b/kayak_font/src/ttf/loader.rs @@ -32,11 +32,9 @@ impl AssetLoader for TTFLoader { load_context: &'a mut LoadContext, ) -> BoxedFuture<'a, Result<(), anyhow::Error>> { Box::pin(async move { - #[cfg(not(target_family = "wasm"))] let asset_io = load_context .asset_io() - .downcast_ref::<FileAssetIo>() - .unwrap(); + .downcast_ref::<FileAssetIo>(); let kttf: KTTF = nanoserde::DeJson::deserialize_json(std::str::from_utf8(bytes).unwrap()).unwrap(); @@ -196,9 +194,13 @@ impl AssetLoader for TTFLoader { let image_bytes = if cache_image.is_err() { #[cfg(not(target_family = "wasm"))] - image_builder - .save(asset_io.root_path().join(cache_path)) - .unwrap(); + { + if let Some(asset_io) = asset_io { + image_builder + .save(asset_io.root_path().join(cache_path)) + .unwrap(); + } + } image_builder.as_bytes().to_vec() } else { let cache_image = cache_image.unwrap(); -- GitLab