Add logging when atlas allocator fails to allocate

Keith Simmons created

Change summary

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(-)

Detailed changes

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,

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)

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();

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(),