From 0ca4c9946a0b01d261a725d2f81858a801cfb23d Mon Sep 17 00:00:00 2001 From: Keith Simmons Date: Mon, 11 Apr 2022 10:31:38 -0700 Subject: [PATCH] Add logging when atlas allocator fails to allocate --- crates/gpui/src/platform/mac/atlas.rs | 14 ++++++++++++-- crates/gpui/src/platform/mac/image_cache.rs | 2 +- crates/gpui/src/platform/mac/renderer.rs | 2 ++ crates/gpui/src/platform/mac/sprite_cache.rs | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/crates/gpui/src/platform/mac/atlas.rs b/crates/gpui/src/platform/mac/atlas.rs index 569a964670..a7a4de1000 100644 --- a/crates/gpui/src/platform/mac/atlas.rs +++ b/crates/gpui/src/platform/mac/atlas.rs @@ -4,6 +4,7 @@ use crate::geometry::{ }; use etagere::BucketedAtlasAllocator; use foreign_types::ForeignType; +use log::warn; use metal::{Device, TextureDescriptor}; use objc::{msg_send, sel, sel_impl}; @@ -41,7 +42,7 @@ impl AtlasAllocator { } pub fn allocate(&mut self, requested_size: Vector2I) -> Option<(AllocId, Vector2I)> { - let (alloc_id, origin) = self + let allocation = self .atlases .last_mut() .unwrap() @@ -51,7 +52,16 @@ impl AtlasAllocator { let (id, origin) = atlas.allocate(requested_size)?; self.atlases.push(atlas); Some((id, origin)) - })?; + }); + + if allocation.is_none() { + warn!( + "allocation of size {:?} could not be created", + requested_size, + ); + } + + let (alloc_id, origin) = allocation?; let id = AllocId { atlas_id: self.atlases.len() - 1, diff --git a/crates/gpui/src/platform/mac/image_cache.rs b/crates/gpui/src/platform/mac/image_cache.rs index 14b7b23986..37129d4fea 100644 --- a/crates/gpui/src/platform/mac/image_cache.rs +++ b/crates/gpui/src/platform/mac/image_cache.rs @@ -33,7 +33,7 @@ impl ImageCache { .remove(&image.id) .or_else(|| self.curr_frame.get(&image.id).copied()) .or_else(|| self.atlases.upload(image.size(), image.as_bytes())) - .ok_or_else(|| anyhow!("Could not upload image of size {:?}", image.size())) + .ok_or_else(|| anyhow!("could not upload image of size {:?}", image.size())) .unwrap(); self.curr_frame.insert(image.id, (alloc_id, atlas_bounds)); (alloc_id, atlas_bounds) diff --git a/crates/gpui/src/platform/mac/renderer.rs b/crates/gpui/src/platform/mac/renderer.rs index 0ecee57a09..b06dabc738 100644 --- a/crates/gpui/src/platform/mac/renderer.rs +++ b/crates/gpui/src/platform/mac/renderer.rs @@ -9,6 +9,7 @@ use crate::{ scene::{Glyph, Icon, Image, Layer, Quad, Scene, Shadow, Underline}, }; use cocoa::foundation::NSUInteger; +use log::warn; use metal::{MTLPixelFormat, MTLResourceOptions, NSRange}; use shaders::ToFloat2 as _; use std::{collections::HashMap, ffi::c_void, iter::Peekable, mem, sync::Arc, vec}; @@ -176,6 +177,7 @@ impl Renderer { let path_allocation = self.path_atlases.allocate(size.to_i32()); if path_allocation.is_none() { // Path size was likely zero. + warn!("could not allocate path texture of size {:?}", size); continue; } let (alloc_id, atlas_origin) = path_allocation.unwrap(); diff --git a/crates/gpui/src/platform/mac/sprite_cache.rs b/crates/gpui/src/platform/mac/sprite_cache.rs index 2d2a604f68..a9e6acb53f 100644 --- a/crates/gpui/src/platform/mac/sprite_cache.rs +++ b/crates/gpui/src/platform/mac/sprite_cache.rs @@ -117,7 +117,7 @@ impl SpriteCache { let (alloc_id, atlas_bounds) = atlases .upload(glyph_bounds.size(), &mask) - .expect("Could not upload glyph"); + .expect("could not upload glyph"); Some(GlyphSprite { atlas_id: alloc_id.atlas_id, atlas_origin: atlas_bounds.origin(),