Skip to content

Conversation

mjakeman
Copy link
Contributor

@mjakeman mjakeman commented Aug 9, 2025

Exposes a Zig equivalent to SetCurrentContext() + SetAllocatorFunctions() for sharing ImGui state across DLL/library boundaries.

I'm using this as part of a hot-reloading mechanism (which relies on shared libraries).

Relevant part of the ImGui docs:

//-----------------------------------------------------------------------------
// [SECTION] CONTEXT AND MEMORY ALLOCATORS
//-----------------------------------------------------------------------------

// DLL users:
// - Heaps and globals are not shared across DLL boundaries!
// - You will need to call SetCurrentContext() + SetAllocatorFunctions() for each static/DLL boundary you are calling from.
// - Same applies for hot-reloading mechanisms that are reliant on reloading DLL (note that many hot-reloading mechanisms work without DLL).
// - Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
// - Confused? In a debugger: add GImGui to your watch window and notice how its value changes depending on your current location (which DLL boundary you are in).

Allows sharing a context across static/DLL boundaries. This is useful
for hot-reloading mechanisms which rely on shared libraries.
zguiSetCurrentContext(ctx);

temp_buffer = std.ArrayList(u8).init(allocator);
temp_buffer.?.resize(3 * 1024 + 1) catch unreachable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this has been copied from init fn but I don't like it. Just making a note.

@hazeycode hazeycode merged commit 068c563 into zig-gamedev:main Aug 9, 2025
3 checks passed
@hazeycode hazeycode linked an issue Aug 9, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit/review temp_buffer
2 participants