Report more information when we panic due to an allocation failure

This commit is contained in:
Nathan Sobo 2022-04-05 13:53:13 -06:00
parent 133d9f947b
commit aeb0b42c7a

View file

@ -2,6 +2,7 @@ use crate::geometry::{
rect::RectI, rect::RectI,
vector::{vec2i, Vector2I}, vector::{vec2i, Vector2I},
}; };
use anyhow::anyhow;
use etagere::BucketedAtlasAllocator; use etagere::BucketedAtlasAllocator;
use foreign_types::ForeignType; use foreign_types::ForeignType;
use metal::{Device, TextureDescriptor}; use metal::{Device, TextureDescriptor};
@ -48,7 +49,12 @@ impl AtlasAllocator {
.allocate(requested_size) .allocate(requested_size)
.unwrap_or_else(|| { .unwrap_or_else(|| {
let mut atlas = self.new_atlas(requested_size); let mut atlas = self.new_atlas(requested_size);
let (id, origin) = atlas.allocate(requested_size).unwrap(); let (id, origin) = atlas
.allocate(requested_size)
.ok_or_else(|| {
anyhow!("could not allocate requested size {:?}", requested_size)
})
.unwrap();
self.atlases.push(atlas); self.atlases.push(atlas);
(id, origin) (id, origin)
}); });