Skip to content

Commit

Permalink
Fixed creating multiple-context (regression in 28ba54a). (#5135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocornut committed Mar 24, 2022
1 parent 1ad8ad6 commit 16ddc16
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
30 changes: 14 additions & 16 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3697,20 +3697,23 @@ void ImGui::GetAllocatorFunctions(ImGuiMemAllocFunc* p_alloc_func, ImGuiMemFreeF

ImGuiContext* ImGui::CreateContext(ImFontAtlas* shared_font_atlas)
{
ImGuiContext* prev_ctx = GetCurrentContext();
ImGuiContext* ctx = IM_NEW(ImGuiContext)(shared_font_atlas);
if (GImGui == NULL)
SetCurrentContext(ctx);
Initialize(ctx);
SetCurrentContext(ctx);
Initialize();
if (prev_ctx != NULL)
SetCurrentContext(prev_ctx); // Restore previous context if any, else keep new one.
return ctx;
}

void ImGui::DestroyContext(ImGuiContext* ctx)
{
ImGuiContext* prev_ctx = GetCurrentContext();
if (ctx == NULL)
ctx = GImGui;
Shutdown(ctx);
if (GImGui == ctx)
SetCurrentContext(NULL);
ctx = prev_ctx;
SetCurrentContext(ctx);
Shutdown();
SetCurrentContext((prev_ctx != ctx) ? prev_ctx : NULL);
IM_DELETE(ctx);
}

Expand Down Expand Up @@ -4464,9 +4467,9 @@ void ImGui::NewFrame()
CallContextHooks(&g, ImGuiContextHookType_NewFramePost);
}

void ImGui::Initialize(ImGuiContext* context)
void ImGui::Initialize()
{
ImGuiContext& g = *context;
ImGuiContext& g = *GImGui;
IM_ASSERT(!g.Initialized && !g.SettingsLoaded);

// Add .ini handle for ImGuiWindow type
Expand Down Expand Up @@ -4496,10 +4499,10 @@ void ImGui::Initialize(ImGuiContext* context)
}

// This function is merely here to free heap allocations.
void ImGui::Shutdown(ImGuiContext* context)
void ImGui::Shutdown()
{
// The fonts atlas can be used prior to calling NewFrame(), so we clear it even if g.Initialized is FALSE (which would happen if we never called NewFrame)
ImGuiContext& g = *context;
ImGuiContext& g = *GImGui;
if (g.IO.Fonts && g.FontAtlasOwnedByContext)
{
g.IO.Fonts->Locked = false;
Expand All @@ -4513,12 +4516,7 @@ void ImGui::Shutdown(ImGuiContext* context)

// Save settings (unless we haven't attempted to load them: CreateContext/DestroyContext without a call to NewFrame shouldn't save an empty file)
if (g.SettingsLoaded && g.IO.IniFilename != NULL)
{
ImGuiContext* backup_context = GImGui;
SetCurrentContext(&g);
SaveIniSettingsToDisk(g.IO.IniFilename);
SetCurrentContext(backup_context);
}

CallContextHooks(&g, ImGuiContextHookType_Shutdown);

Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Index of this file:
// Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.88 WIP"
#define IMGUI_VERSION_NUM 18710
#define IMGUI_VERSION_NUM 18711
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE

Expand Down
4 changes: 2 additions & 2 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2519,8 +2519,8 @@ namespace ImGui
IMGUI_API ImDrawList* GetForegroundDrawList(ImGuiViewport* viewport); // get foreground draw list for the given viewport. this draw list will be the last rendered one. Useful to quickly draw shapes/text over dear imgui contents.

// Init
IMGUI_API void Initialize(ImGuiContext* context);
IMGUI_API void Shutdown(ImGuiContext* context); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().
IMGUI_API void Initialize();
IMGUI_API void Shutdown(); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().

// NewFrame
IMGUI_API void UpdateInputEvents(bool trickle_fast_inputs);
Expand Down

0 comments on commit 16ddc16

Please sign in to comment.