Add logging when atlas allocator fails to allocate
This commit is contained in:
parent
7abd3a98a8
commit
0ca4c9946a
4 changed files with 16 additions and 4 deletions
|
@ -4,6 +4,7 @@ use crate::geometry::{
|
||||||
};
|
};
|
||||||
use etagere::BucketedAtlasAllocator;
|
use etagere::BucketedAtlasAllocator;
|
||||||
use foreign_types::ForeignType;
|
use foreign_types::ForeignType;
|
||||||
|
use log::warn;
|
||||||
use metal::{Device, TextureDescriptor};
|
use metal::{Device, TextureDescriptor};
|
||||||
use objc::{msg_send, sel, sel_impl};
|
use objc::{msg_send, sel, sel_impl};
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ impl AtlasAllocator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocate(&mut self, requested_size: Vector2I) -> Option<(AllocId, Vector2I)> {
|
pub fn allocate(&mut self, requested_size: Vector2I) -> Option<(AllocId, Vector2I)> {
|
||||||
let (alloc_id, origin) = self
|
let allocation = self
|
||||||
.atlases
|
.atlases
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -51,7 +52,16 @@ impl AtlasAllocator {
|
||||||
let (id, origin) = atlas.allocate(requested_size)?;
|
let (id, origin) = atlas.allocate(requested_size)?;
|
||||||
self.atlases.push(atlas);
|
self.atlases.push(atlas);
|
||||||
Some((id, origin))
|
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 {
|
let id = AllocId {
|
||||||
atlas_id: self.atlases.len() - 1,
|
atlas_id: self.atlases.len() - 1,
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl ImageCache {
|
||||||
.remove(&image.id)
|
.remove(&image.id)
|
||||||
.or_else(|| self.curr_frame.get(&image.id).copied())
|
.or_else(|| self.curr_frame.get(&image.id).copied())
|
||||||
.or_else(|| self.atlases.upload(image.size(), image.as_bytes()))
|
.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();
|
.unwrap();
|
||||||
self.curr_frame.insert(image.id, (alloc_id, atlas_bounds));
|
self.curr_frame.insert(image.id, (alloc_id, atlas_bounds));
|
||||||
(alloc_id, atlas_bounds)
|
(alloc_id, atlas_bounds)
|
||||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
||||||
scene::{Glyph, Icon, Image, Layer, Quad, Scene, Shadow, Underline},
|
scene::{Glyph, Icon, Image, Layer, Quad, Scene, Shadow, Underline},
|
||||||
};
|
};
|
||||||
use cocoa::foundation::NSUInteger;
|
use cocoa::foundation::NSUInteger;
|
||||||
|
use log::warn;
|
||||||
use metal::{MTLPixelFormat, MTLResourceOptions, NSRange};
|
use metal::{MTLPixelFormat, MTLResourceOptions, NSRange};
|
||||||
use shaders::ToFloat2 as _;
|
use shaders::ToFloat2 as _;
|
||||||
use std::{collections::HashMap, ffi::c_void, iter::Peekable, mem, sync::Arc, vec};
|
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());
|
let path_allocation = self.path_atlases.allocate(size.to_i32());
|
||||||
if path_allocation.is_none() {
|
if path_allocation.is_none() {
|
||||||
// Path size was likely zero.
|
// Path size was likely zero.
|
||||||
|
warn!("could not allocate path texture of size {:?}", size);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (alloc_id, atlas_origin) = path_allocation.unwrap();
|
let (alloc_id, atlas_origin) = path_allocation.unwrap();
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl SpriteCache {
|
||||||
|
|
||||||
let (alloc_id, atlas_bounds) = atlases
|
let (alloc_id, atlas_bounds) = atlases
|
||||||
.upload(glyph_bounds.size(), &mask)
|
.upload(glyph_bounds.size(), &mask)
|
||||||
.expect("Could not upload glyph");
|
.expect("could not upload glyph");
|
||||||
Some(GlyphSprite {
|
Some(GlyphSprite {
|
||||||
atlas_id: alloc_id.atlas_id,
|
atlas_id: alloc_id.atlas_id,
|
||||||
atlas_origin: atlas_bounds.origin(),
|
atlas_origin: atlas_bounds.origin(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue