From 7abf8afd16eeb2aacf7671a1e8989cf9758ec0af Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 21 Nov 2023 17:13:46 +0100 Subject: [PATCH] Change `Arc` to `Rc` (#3598) This is required for Rust 1.72 (for unknown reasons; see https://github.com/emilk/egui/pull/3595), but also for updating to glow 0.13, where the `glow::Context` is not longer `Sync+Send` --- crates/eframe/src/epi.rs | 6 +++--- crates/eframe/src/native/epi_integration.rs | 2 +- crates/eframe/src/native/glow_integration.rs | 2 +- crates/eframe/src/web/web_painter_glow.rs | 4 ++-- crates/egui_glow/examples/pure_glow.rs | 2 +- crates/egui_glow/src/painter.rs | 8 ++++---- crates/egui_glow/src/winit.rs | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index d5ef2a5aa2f..848b144c186 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -64,7 +64,7 @@ pub struct CreationContext<'s> { /// /// Only available when compiling with the `glow` feature and using [`Renderer::Glow`]. #[cfg(feature = "glow")] - pub gl: Option>, + pub gl: Option>, /// The underlying WGPU render state. /// @@ -602,7 +602,7 @@ pub struct Frame { /// A reference to the underlying [`glow`] (OpenGL) context. #[cfg(feature = "glow")] - pub(crate) gl: Option>, + pub(crate) gl: Option>, /// Can be used to manage GPU resources for custom rendering with WGPU using [`egui::PaintCallback`]s. #[cfg(feature = "wgpu")] @@ -674,7 +674,7 @@ impl Frame { /// To get a [`glow`] context you need to compile with the `glow` feature flag, /// and run eframe using [`Renderer::Glow`]. #[cfg(feature = "glow")] - pub fn gl(&self) -> Option<&std::sync::Arc> { + pub fn gl(&self) -> Option<&std::rc::Rc> { self.gl.as_ref() } diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index 3a868639a6e..082c82b6d58 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -143,7 +143,7 @@ impl EpiIntegration { native_options: &crate::NativeOptions, storage: Option>, is_desktop: bool, - #[cfg(feature = "glow")] gl: Option>, + #[cfg(feature = "glow")] gl: Option>, #[cfg(feature = "wgpu")] wgpu_render_state: Option, ) -> Self { let egui_ctx = egui::Context::default(); diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 5c7f3371ed4..21ea63fa19f 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -163,7 +163,7 @@ impl GlowWinitApp { let gl = unsafe { crate::profile_scope!("glow::Context::from_loader_function"); - Arc::new(glow::Context::from_loader_function(|s| { + Rc::new(glow::Context::from_loader_function(|s| { let s = std::ffi::CString::new(s) .expect("failed to construct C string from string for gl proc address"); diff --git a/crates/eframe/src/web/web_painter_glow.rs b/crates/eframe/src/web/web_painter_glow.rs index b12ac1cefaa..e02c6dd973a 100644 --- a/crates/eframe/src/web/web_painter_glow.rs +++ b/crates/eframe/src/web/web_painter_glow.rs @@ -15,7 +15,7 @@ pub(crate) struct WebPainterGlow { } impl WebPainterGlow { - pub fn gl(&self) -> &std::sync::Arc { + pub fn gl(&self) -> &std::rc::Rc { self.painter.gl() } @@ -24,7 +24,7 @@ impl WebPainterGlow { let (gl, shader_prefix) = init_glow_context_from_canvas(&canvas, options.webgl_context_option)?; - let gl = std::sync::Arc::new(gl); + let gl = std::rc::Rc::new(gl); let painter = egui_glow::Painter::new(gl, shader_prefix, None) .map_err(|err| format!("Error starting glow painter: {err}"))?; diff --git a/crates/egui_glow/examples/pure_glow.rs b/crates/egui_glow/examples/pure_glow.rs index 5df4d23ecdf..5709a4d03e6 100644 --- a/crates/egui_glow/examples/pure_glow.rs +++ b/crates/egui_glow/examples/pure_glow.rs @@ -152,7 +152,7 @@ fn main() { let event_loop = winit::event_loop::EventLoopBuilder::::with_user_event().build(); let (gl_window, gl) = create_display(&event_loop); - let gl = std::sync::Arc::new(gl); + let gl = std::rc::Rc::new(gl); let mut egui_glow = egui_glow::EguiGlow::new(&event_loop, gl.clone(), None, None); diff --git a/crates/egui_glow/src/painter.rs b/crates/egui_glow/src/painter.rs index 2b10340105b..65575b63790 100644 --- a/crates/egui_glow/src/painter.rs +++ b/crates/egui_glow/src/painter.rs @@ -1,7 +1,7 @@ #![allow(clippy::collapsible_else_if)] #![allow(unsafe_code)] -use std::{collections::HashMap, sync::Arc}; +use std::{collections::HashMap, rc::Rc}; use egui::{ emath::Rect, @@ -60,7 +60,7 @@ impl From for PainterError { /// This struct must be destroyed with [`Painter::destroy`] before dropping, to ensure OpenGL /// objects have been properly deleted and are not leaked. pub struct Painter { - gl: Arc, + gl: Rc, max_texture_side: usize, @@ -118,7 +118,7 @@ impl Painter { /// * failed to create postprocess on webgl with `sRGB` support /// * failed to create buffer pub fn new( - gl: Arc, + gl: Rc, shader_prefix: &str, shader_version: Option, ) -> Result { @@ -248,7 +248,7 @@ impl Painter { } /// Access the shared glow context. - pub fn gl(&self) -> &Arc { + pub fn gl(&self) -> &Rc { &self.gl } diff --git a/crates/egui_glow/src/winit.rs b/crates/egui_glow/src/winit.rs index ce91bfa76f0..1b4ebf46833 100644 --- a/crates/egui_glow/src/winit.rs +++ b/crates/egui_glow/src/winit.rs @@ -24,7 +24,7 @@ impl EguiGlow { /// For automatic shader version detection set `shader_version` to `None`. pub fn new( event_loop: &winit::event_loop::EventLoopWindowTarget, - gl: std::sync::Arc, + gl: std::rc::Rc, shader_version: Option, native_pixels_per_point: Option, ) -> Self {