Avoid generating empty caches in iced_wgpu

This commit is contained in:
Héctor Ramón Jiménez 2024-04-06 03:06:40 +02:00
parent 7eb16452f3
commit 441aac2599
No known key found for this signature in database
GPG key ID: 4C07CEC81AFA161F
4 changed files with 66 additions and 22 deletions

View file

@ -38,8 +38,8 @@ pub enum Geometry {
#[derive(Clone)]
pub struct Cache {
pub meshes: triangle::Cache,
pub text: text::Cache,
pub meshes: Option<triangle::Cache>,
pub text: Option<text::Cache>,
}
impl Cached for Geometry {
@ -53,8 +53,17 @@ impl Cached for Geometry {
match self {
Self::Live { meshes, text } => {
if let Some(mut previous) = previous {
previous.meshes.update(meshes);
previous.text.update(text);
if let Some(cache) = &mut previous.meshes {
cache.update(meshes);
} else {
previous.meshes = triangle::Cache::new(meshes);
}
if let Some(cache) = &mut previous.text {
cache.update(text);
} else {
previous.text = text::Cache::new(text);
}
previous
} else {