From c9b39bf3f35fa829a0e08f67a9d6e7ba468bd6c6 Mon Sep 17 00:00:00 2001 From: Charlotte McElwain Date: Wed, 8 May 2024 15:23:03 -0700 Subject: [PATCH] Fix draw reset. --- bevy_nannou_draw/src/draw/mod.rs | 6 ++++-- nannou/src/app.rs | 10 +++++++--- nannou/src/window.rs | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bevy_nannou_draw/src/draw/mod.rs b/bevy_nannou_draw/src/draw/mod.rs index ed74019f9..f532f2b60 100644 --- a/bevy_nannou_draw/src/draw/mod.rs +++ b/bevy_nannou_draw/src/draw/mod.rs @@ -193,7 +193,7 @@ impl State { self.last_draw_context = None; self.background_color = None; self.drawing.clear(); - // self.materials.clear(); + self.materials.clear(); self.draw_commands.clear(); self.intermediary_state.write().unwrap().reset(); } @@ -253,9 +253,10 @@ where /// Resets all state within the `Draw` instance. pub fn reset(&mut self) { self.state.write().unwrap().reset(); + self.insert_default_material(); } - fn insert_default_material(&self) { + fn insert_default_material(&mut self) { let mut state = self.state.write().unwrap(); let material = M::default(); let material_id = UntypedAssetId::Uuid { @@ -263,6 +264,7 @@ where uuid: Uuid::new_v4(), }; state.materials.insert(material_id, Box::new(material)); + self.material = material_id; } // Context changes. diff --git a/nannou/src/app.rs b/nannou/src/app.rs index 7f624e705..abc3d604b 100644 --- a/nannou/src/app.rs +++ b/nannou/src/app.rs @@ -37,7 +37,7 @@ use bevy_nannou::NannouPlugin; use crate::prelude::bevy_ecs::system::lifetimeless::Read; use crate::prelude::bevy_ecs::system::SystemState; -use crate::prelude::bevy_reflect::{ReflectMut, ReflectOwned, ReflectRef, TypeInfo}; +use crate::prelude::bevy_reflect::{ApplyError, ReflectMut, ReflectOwned, ReflectRef, TypeInfo}; use crate::prelude::render::{NannouMaterial, NannouMesh, NannouPersistentMesh}; use crate::window::WindowUserFunctions; use crate::{geom, window}; @@ -95,7 +95,7 @@ pub struct SketchBuilder { #[derive(Debug, Clone)] enum DefaultWindowSize { /// Default window size in logical coordinates. - Logical([f32; 2]), + Logical([u32; 2]), /// Fullscreen on whatever the primary monitor is at the time of window creation. Fullscreen, } @@ -257,7 +257,7 @@ where /// If a window is created and its size is not specified, this size will be used. pub fn size(mut self, width: u32, height: u32) -> Self { self.config.default_window_size = - Some(DefaultWindowSize::Logical([width as f32, height as f32])); + Some(DefaultWindowSize::Logical([width, height])); self } @@ -437,6 +437,10 @@ where self.0.apply(value) } + fn try_apply(&mut self, value: &dyn Reflect) -> Result<(), ApplyError> { + self.0.try_apply(value) + } + fn set(&mut self, value: Box) -> Result<(), Box> { self.0.set(value) } diff --git a/nannou/src/window.rs b/nannou/src/window.rs index 5aeed27ad..1515538ed 100644 --- a/nannou/src/window.rs +++ b/nannou/src/window.rs @@ -461,9 +461,9 @@ where /// /// This describes to the "inner" part of the window, not including desktop decorations like the /// title bar. - pub fn size(self, width: f32, height: f32) -> Self { + pub fn size(self, width: u32, height: u32) -> Self { self.map_window(|mut w| { - w.resolution.set(width, height); + w.resolution.set(width as f32, height as f32); w }) }