diff --git a/src/gui/platform/android/mod.rs b/src/gui/platform/android/mod.rs index ca2d230..1b1f1b5 100644 --- a/src/gui/platform/android/mod.rs +++ b/src/gui/platform/android/mod.rs @@ -13,10 +13,11 @@ // limitations under the License. use lazy_static::lazy_static; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; +use parking_lot::RwLock; + use jni::JNIEnv; use jni::objects::{JByteArray, JObject, JString, JValue}; - use winit::platform::android::activity::AndroidApp; use crate::gui::platform::PlatformCallbacks; @@ -84,7 +85,7 @@ impl PlatformCallbacks for Android { fn start_camera(&self) { // Clear image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; // Start camera. self.call_java_method("startCamera", "()V", &[]).unwrap(); @@ -94,12 +95,12 @@ impl PlatformCallbacks for Android { // Stop camera. self.call_java_method("stopCamera", "()V", &[]).unwrap(); // Clear image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; } fn camera_image(&self) -> Option<(Vec, u32)> { - let r_image = LAST_CAMERA_IMAGE.read().unwrap(); + let r_image = LAST_CAMERA_IMAGE.read(); if r_image.is_some() { return Some(r_image.clone().unwrap()); } @@ -134,7 +135,6 @@ pub extern "C" fn Java_mw_gri_android_MainActivity_onCameraImage( ) { let arr = unsafe { JByteArray::from_raw(buff) }; let image : Vec = env.convert_byte_array(arr).unwrap(); - if let Ok(mut w_image) = LAST_CAMERA_IMAGE.write() { - *w_image = Some((image, rotation as u32)); - } + let mut w_image = LAST_CAMERA_IMAGE.write(); + *w_image = Some((image, rotation as u32)); } \ No newline at end of file diff --git a/src/gui/platform/desktop/mod.rs b/src/gui/platform/desktop/mod.rs index 8005c40..39456f4 100644 --- a/src/gui/platform/desktop/mod.rs +++ b/src/gui/platform/desktop/mod.rs @@ -13,7 +13,8 @@ // limitations under the License. use lazy_static::lazy_static; -use std::sync::{Arc, RwLock}; +use std::sync::Arc; +use parking_lot::RwLock; use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; use std::thread; use eye::hal::PlatformContext; @@ -56,7 +57,7 @@ impl PlatformCallbacks for Desktop { fn start_camera(&self) { // Clear image. { - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; } @@ -107,17 +108,17 @@ impl PlatformCallbacks for Desktop { // Get data from frame. if let Ok(frame_data) = frame { // Save image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = Some((frame_data.to_vec(), 0)); } else { // Clear image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; break; } } else { // Clear image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; break; } @@ -131,14 +132,14 @@ impl PlatformCallbacks for Desktop { // Stop camera. self.stop_camera.store(true, Ordering::Relaxed); // Clear image. - let mut w_image = LAST_CAMERA_IMAGE.write().unwrap(); + let mut w_image = LAST_CAMERA_IMAGE.write(); *w_image = None; } fn camera_image(&self) -> Option<(Vec, u32)> { - let r_image = LAST_CAMERA_IMAGE.read().unwrap(); + let r_image = LAST_CAMERA_IMAGE.read(); if r_image.is_some() { - return Some(r_image.clone().unwrap()); + return r_image.clone(); } None }