INNER CODE UNIT · Rust
texture_context
PistonDevelopers/piston_window · src/piston_script.rs:253
let texture_context = unsafe {&mut *Current::<TextureContext>::new()};
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(