pcmd.UserCallback is not null

I have been trying to get ImGui running, but I keep getting the UserCallback field of DrawCmd as being not null. It should be NULL since I am not setting any draw callback. Anyone faced this before? Seems to be very particular. Tried on both windows and linux, it segfaults when I call the function (the pointer value is small like 0x1 or 0x6). I’m using the opengl3 + glfw example implementation.
Just want to know if someone else has also faced this problem?

There’s maybe a mismatch between how your different compilation units are seeing the structure.
Do you have any modification meant for imconfig.h (generally #define) defined anywhere else?

Try printing sizeof(ImDrawCmd) and IM_OFFSET(ImDrawCmd, field_name) from different .cpp files.

Or, you have a classic memory overwrite but that sounds less likely.

1 Like

That was exactly it. I made a silly error. I #defined ImTextureID to GLuint in my source file before including imgui.h, but imgui.cpp and the other imgui files included imconfig.h without ImTextureID redefined. Sorry for this rather silly mistake.

Note that you don’t need this #define if you are going to store a GLuint.
Just call your GLuint to void*, it fits perfectly.