diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index f7c57ef015..03cd7008c7 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -34,11 +34,11 @@ use util::{ResultExt, debug_panic}; #[cfg(any(feature = "inspector", debug_assertions))] use crate::InspectorElementRegistry; use crate::{ - Action, ActionBuildError, ActionRegistry, Any, AnyView, AnyWindowHandle, AppContext, Asset, - AssetSource, BackgroundExecutor, Bounds, ClipboardItem, CursorStyle, DispatchPhase, DisplayId, - EventEmitter, FocusHandle, FocusMap, ForegroundExecutor, Global, KeyBinding, KeyContext, - Keymap, Keystroke, LayoutId, Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, Platform, - PlatformDisplay, PlatformKeyboardLayout, PlatformKeyboardMapper, Point, Priority, + Action, ActionBuildError, ActionRegistry, Any, AnyView, AnyWindowHandle, AppContext, Arena, + Asset, AssetSource, BackgroundExecutor, Bounds, ClipboardItem, CursorStyle, DispatchPhase, + DisplayId, EventEmitter, FocusHandle, FocusMap, ForegroundExecutor, Global, KeyBinding, + KeyContext, Keymap, Keystroke, LayoutId, Menu, MenuItem, OwnedMenu, PathPromptOptions, Pixels, + Platform, PlatformDisplay, PlatformKeyboardLayout, PlatformKeyboardMapper, Point, Priority, PromptBuilder, PromptButton, PromptHandle, PromptLevel, Render, RenderImage, RenderablePromptHandle, Reservation, ScreenCaptureSource, SharedString, SubscriberSet, Subscription, SvgRenderer, Task, TextSystem, Window, WindowAppearance, WindowHandle, WindowId, @@ -637,6 +637,9 @@ pub struct App { pub(crate) name: Option<&'static str>, quit_mode: QuitMode, quitting: bool, + /// Per-App element arena. This isolates element allocations between different + /// App instances (important for tests where multiple Apps run concurrently). + pub(crate) element_arena: RefCell, } impl App { @@ -713,6 +716,7 @@ impl App { #[cfg(any(test, feature = "test-support", debug_assertions))] name: None, + element_arena: RefCell::new(Arena::new(1024 * 1024)), }), }); diff --git a/crates/gpui/src/element.rs b/crates/gpui/src/element.rs index 2c695486c5..90038e82f7 100644 --- a/crates/gpui/src/element.rs +++ b/crates/gpui/src/element.rs @@ -32,9 +32,9 @@ //! your own custom layout algorithm or rendering a code editor. use crate::{ - App, ArenaBox, AvailableSpace, Bounds, Context, DispatchNodeId, ELEMENT_ARENA, ElementId, - FocusHandle, InspectorElementId, LayoutId, Pixels, Point, Size, Style, Window, - util::FluentBuilder, + App, ArenaBox, AvailableSpace, Bounds, Context, DispatchNodeId, ElementId, FocusHandle, + InspectorElementId, LayoutId, Pixels, Point, Size, Style, Window, util::FluentBuilder, + window::with_element_arena, }; use derive_more::{Deref, DerefMut}; use std::{ @@ -579,8 +579,7 @@ impl AnyElement { E: 'static + Element, E::RequestLayoutState: Any, { - let element = ELEMENT_ARENA - .with_borrow_mut(|arena| arena.alloc(|| Drawable::new(element))) + let element = with_element_arena(|arena| arena.alloc(|| Drawable::new(element))) .map(|element| element as &mut dyn ElementObject); AnyElement(element) }