floooh / sokol-zig

Zig bindings for the sokol headers (https://github.com/floooh/sokol)
zlib License
376 stars 48 forks source link

sokol_imgui.h: C++ error: member reference base type 'ImDrawList **' (aka 'struct ImDrawList **') is not a structure or union #72

Closed Namek closed 4 months ago

Namek commented 4 months ago

Hi!

I have added sokol-zig to my project per this url in build.zig.zon: git+https://github.com/floooh/sokol-zig.git#ca76d1e66b2539a6614535aaad39d0168985a2e9

and then of course my build.zig:

const dep_sokol = b.dependency("sokol", .{
    .target = target,
    .optimize = optimize,
    .with_sokol_imgui = true,
});
dep_sokol.artifact("sokol_clib").addIncludePath(b.path("deps/")); // I have custom cimgui.h which includes the original "cimgui/cimgui.h" from there
exe.root_module.addImport("sokol", dep_sokol.module("sokol"));

And here I got some C++ error:

/Users/namek/.cache/zig/p/122055d69396139fc4b51ba859a2af304608e336572084ed44c5c79504be9ae2aba8/src/sokol/c/sokol_imgui.h:2587:35: error: member reference base type 'ImDrawList **' (aka 'struct ImDrawList **') is not a structure or union
        return draw_data->CmdLists.Data[cl_index];
               ~~~~~~~~~~~~~~~~~~~^~
/Users/namek/.cache/zig/p/122055d69396139fc4b51ba859a2af304608e336572084ed44c5c79504be9ae2aba8/src/sokol/c/sokol_imgui.c:9:10: note: in file included from /Users/namek/.cache/zig/p/122055d69396139fc4b51ba859a2af304608e336572084ed44c5c79504be9ae2aba8/src/sokol/c/sokol_imgui.c:9:
#include "sokol_imgui.h"
         ^

Any ideas what's wrong?

My (c)imgui is "1.89.7"

Namek commented 4 months ago

My custom cimgui.h:

#ifndef __IMGUI_ZIG__H
#define __IMGUI_ZIG__H

// without this ifndef it would error about redefining it
#ifndef CIMGUI_DEFINE_ENUMS_AND_STRUCTS
  #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS 1
#endif

#include "./cimgui/cimgui.h"

// because Zig doesn't support c.igGetCurrentWindow().*.DC.CursorPosPrevLine;
EXTERN ImGuiWindowTempData* igGetCurrentWindowRead_DC();
EXTERN ImGuiID igDockBuilderGetNodeID(ImGuiID node_id);

#endif

I tried including the original cimgui.h by doing the path change like this:

dep_sokol.artifact("sokol_clib").addIncludePath(b.path("deps/cimgui"));

so it would get the deps/cimgui/cimgui.h. The error stays the same.

It seems the error is about this place:

static ImDrawList* _simgui_imdrawlist_at(ImDrawData* draw_data, int cl_index) {
    #if defined(__cplusplus)
        return draw_data->CmdLists[cl_index];
    #else
        return draw_data->CmdLists.Data[cl_index];  // <!--- this line
    #endif
}
floooh commented 4 months ago

This was a breaking change between cimgui 1.89 and 1.90, you basically need to update to a more recent ImGui version to use the sokol imgui bindings:

https://github.com/floooh/sokol/commit/d4ac122f36d7659a18b312fd4fa2317fb9e06a63#diff-cb6a37081b7b34f6ee0cc996c9a756b99a750ac7fde63297b57d23433a659b5c

floooh commented 4 months ago

PS: or rather the breakage seems to have been introduced in cimgui 1.89.9, not in 1.90

https://github.com/floooh/sokol/issues/879