From 7c084caa1a582075f0d5895313ef7c4a31abe3b9 Mon Sep 17 00:00:00 2001 From: Dominik Gschwind Date: Tue, 18 Aug 2020 12:59:49 +0200 Subject: [PATCH] Fixed `SharedFontAtlas` not being used When creating a new imgui context, the optional shared font atlas was not being used. --- src/context.rs | 11 ++++++++++- src/fonts/atlas.rs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/context.rs b/src/context.rs index 48fb352..f032ba2 100644 --- a/src/context.rs +++ b/src/context.rs @@ -209,9 +209,18 @@ impl Context { no_current_context(), "A new active context cannot be created, because another one already exists" ); + + let shared_font_atlas_ptr = match &shared_font_atlas { + Some(shared_font_atlas) => { + let borrowed_font_atlas = shared_font_atlas.borrow(); + borrowed_font_atlas.0 + } + None => ptr::null_mut(), + }; // Dear ImGui implicitly sets the current context during igCreateContext if the current // context doesn't exist - let raw = unsafe { sys::igCreateContext(ptr::null_mut()) }; + let raw = unsafe { sys::igCreateContext(shared_font_atlas_ptr) }; + Context { raw, shared_font_atlas, diff --git a/src/fonts/atlas.rs b/src/fonts/atlas.rs index a3d5c84..80401ad 100644 --- a/src/fonts/atlas.rs +++ b/src/fonts/atlas.rs @@ -409,7 +409,7 @@ pub struct FontAtlasTexture<'a> { /// A font atlas that can be shared between contexts #[derive(Debug)] -pub struct SharedFontAtlas(*mut sys::ImFontAtlas); +pub struct SharedFontAtlas(pub(crate) *mut sys::ImFontAtlas); impl SharedFontAtlas { pub fn create() -> SharedFontAtlas {