Skip to main content
Context management functions allow you to create, destroy, and switch between multiple Dear ImGui contexts. Each context maintains its own state, including font atlas, style, and window data.
Each context creates its own ImFontAtlas by default. You can share a font atlas between contexts by passing it to CreateContext().

CreateContext

Creates a new Dear ImGui context.

Parameters

ImFontAtlas*
default:"NULL"
Optional font atlas to share between contexts. If NULL, a new font atlas will be created.

Returns

ImGuiContext*
Pointer to the newly created context.

Example

For DLL users: heaps and globals are not shared across DLL boundaries. You must call SetCurrentContext() + SetAllocatorFunctions() for each static/DLL boundary.

DestroyContext

Destroys a Dear ImGui context and frees all associated resources.

Parameters

ImGuiContext*
default:"NULL"
The context to destroy. If NULL, destroys the current context.

Example

Always destroy contexts before application shutdown to prevent memory leaks.

GetCurrentContext

Retrieves the currently active Dear ImGui context.

Returns

ImGuiContext*
Pointer to the current context, or NULL if no context is set.

Example

SetCurrentContext

Sets the active Dear ImGui context. All subsequent ImGui calls will operate on this context.

Parameters

ImGuiContext*
required
The context to make active.

Example

When switching contexts, make sure to complete the frame (call Render() or EndFrame()) before switching to avoid state corruption.

Multi-Context Usage Pattern