INNER CODE UNIT · Rust

images

PistonDevelopers/piston_window · src/piston_script.rs:254

                let images = unsafe { &*Current::<Vec<RgbaImage>>::new() };
                let textures = unsafe { &mut *Current::<Vec<Texture>>::new() };
                let image: &RgbaImage = if let Some(x) = images.get(id as usize) {x}
                            else {return Err("Image id is out of bounds".into())};

                let new_id = textures.len();
                textures.push(Texture::from_image(texture_context, image, &TextureSettings::new())
                    .map_err(|_| "Could not create texture".to_string())?);
                Ok(new_id.push_var())
            }
            Variable::RustObject(obj) => {
                let texture_context = unsafe {&mut *Current::<TextureContext>::new()};
                let mut guard = obj.lock().map_err(|_| "Could not obtain lock on Mutex".to_string())?;
                let image: &mut RgbaImage = guard.downcast_mut()
                    .ok_or_else(|| "Expected RgbaImage".to_string())?;

                Ok(Variable::RustObject(
                    to_rust_object(Texture::from_image(texture_context, image, &TextureSettings::new()))))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…