diff --git a/crates/processing_pyo3/examples/background_image.py b/crates/processing_pyo3/examples/background_image.py index 9c07e58..3cdaa55 100644 --- a/crates/processing_pyo3/examples/background_image.py +++ b/crates/processing_pyo3/examples/background_image.py @@ -1,7 +1,5 @@ from processing import * -i = None - def setup(): global i size(800, 600) @@ -9,9 +7,7 @@ def setup(): def draw(): - global i background(220, 100, 24) - # i = image("images/logo.png") background(i) diff --git a/crates/processing_pyo3/src/graphics.rs b/crates/processing_pyo3/src/graphics.rs index ead97a6..00245f8 100644 --- a/crates/processing_pyo3/src/graphics.rs +++ b/crates/processing_pyo3/src/graphics.rs @@ -24,17 +24,16 @@ impl Drop for Surface { } #[pyclass] -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Image { entity: Entity, } -// TODO: we lose the image if this is implemented, meaning that the image is getting dropped prematurely -// impl Drop for Image { -// fn drop(&mut self) { -// let _ = image_destroy(self.entity); -// } -// } +impl Drop for Image { + fn drop(&mut self) { + let _ = image_destroy(self.entity); + } +} #[pyclass(unsendable)] pub struct Graphics { @@ -84,7 +83,7 @@ impl Graphics { .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } - pub fn background_image(&self, image: Image) -> PyResult<()> { + pub fn background_image(&self, image: &Image) -> PyResult<()> { graphics_record_command(self.entity, DrawCommand::BackgroundImage(image.entity)) .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index dd592f3..3e5d07a 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -102,7 +102,7 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> { fn background(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> { let first = args.get_item(0)?; if first.is_instance_of::() { - get_graphics(module)?.background_image(first.extract::()?) + get_graphics(module)?.background_image(&*first.extract::>()?) } else { get_graphics(module)?.background(args.extract()?) }