Stop using obsolete ImGui functions and enums - #2412
Conversation
- enable IMGUI_DISABLE_OBSOLETE_FUNCTIONS in imconfig.h and port the deprecated uses: tab/nav colour enums, the NavNoCaptureKeyboard flag, clipboard callbacks, Image() to ImageWithBg(), and DX12 legacy SRV descriptors. - make an inline version of Initialize() so IMGUI_CHECKVERSION() runs in the caller's translation unit, where it can catch an app/library config mismatch instead of only comparing the Cinder lib version to itself. - to resolve issue cinder#2411.
|
Verified against samples/D3d12ImageBasic: the allocator and free callbacks are exercised for ImGui's font atlas and the UI renders correctly. The multi-descriptor path (more than one texture live at once in DX12) is not exercised by any existing sample. |
- removed IgnoreSpecificDefaultLibraries (LIBCMT;LIBCPMT) from samples/ImGui, which broke its Release x64 link (/MT requests exactly the libs being ignored, so the CRT was excluded with thousands of unresolved symbols). - the same line appears in 67 sample projects; fixing the others seems out of scope here but is probably worth a separate pass.
|
Fixed broken Release build for
|
|
One last comment -- the most important part of this fix is the protection provided by doing |
- the ListBoxHeader() -> BeginListBox() port passed 'height_in_items' as a pixel height, so the default of -1 became a negative size and collapsed the list to a few pixels. Restore the old semantics: -1 means min(count, 7) rows.
|
Also fixed regression when using the default height (-1) with |
- PostDraw() skipped Render() during a modal loop but set sTriggerNewFrame true, so the dialog's repaints called NewFrame() on the frame already open, asserting (and crashing on cancel of e.g. with getOpenFilePath()). - leaving the flag clear is enough: the outer draw finishes the open frame as soon as the dialog returns.
|
Sorry, that latest commit cc0b1f3 (about the ImGui assert) probably shouldn't have been added to this PR related to "obsolete ImGui functions". It probably deserved its own PR. Is anyone reviewing these PRs and likely to merge them in? 🤞 🙏 Thanks! |
Summary:
Breaking change -- needs a maintainer decision
Enabling
IMGUI_DISABLE_OBSOLETE_FUNCTIONSaffects downstream apps, not just Cinder. The most likely thing people hit is renamed colour enums, since many people might customizestyle.Colors[]:ImGuiCol_TabActiveImGuiCol_TabSelectedImGuiCol_TabUnfocusedImGuiCol_TabDimmedImGuiCol_TabUnfocusedActiveImGuiCol_TabDimmedSelectedImGuiCol_NavHighlightImGuiCol_NavCursorImGuiChildFlags_BorderImGuiChildFlags_BordersImGuiTreeNodeFlags_AllowItemOverlap...AllowOverlapplus a handful of functions (
SetWindowFontScale(),GetContentRegionMax(),SetItemAllowOverlap(), the oldCombo()/ListBox()callback form) and theio.FontGlobalScale/io.*ClipboardTextFnmembers.The blast radius is bounded: everything obsoleted before ~1.89 is already fully commented out in 1.92, so it is unavailable with or without this macro change! Only the dozen or so items still live in the obsolete section are affected here.
If that's too disruptive, the macro is a single line in
imconfig.hand I'm happy to comment it out -- the internal migration stands on its own, since these APIs will be deleted upstream eventually.Initialize()/InitializeImpl()splitIMGUI_CHECKVERSION()only detects a config mismatch when it is compiled in the caller's translation unit. The existing call inCinderImGui.cppcompares Cinder against itself and can never fail, which is why #2411 went undiagnosed. MakingInitialize()an inline header wrapper is the smallest way to get the check instantiated in application code with no change to how apps call it.Worth flagging: this moves the exported symbol from
InitializetoInitializeImpl, so it is an ABI change for anyone linking a prebuiltcinder.lib. Rebuilding resolves it. If you'd prefer a different shape (a separateImGui::CheckVersion()helper apps call themselves, or a differently named impl function), I could adjust it.One migration that is not a simple rename
Image()→ImageWithBg()is the only case where the compiler won't catch you: the old signature took(tint_col, border_col), the new one takes(bg_col, tint_col). Forwarding positionally compiles cleanly and renders incorrectly -- I hit that before spotting it.Cinder's public
ImGui::Image( Texture2dRef, size, uv0, uv1, tint, border )signature is unchanged, andborder_colis still honoured viaImGuiCol_BorderplusImGuiStyleVar_ImageBorderSize, mirroring ImGui's own obsolete shim inimgui_widgets.cpp(including forcing a minimum thickness when the colour has alpha, so a border still appears purely because a colour was supplied). However, the Cinder version of ImGui::Image() still takes the same arguments and order as before, so anyone using that (such assamples/ImGuiwill continue to work as before).DX12 is untested
I wrote the SRV descriptor allocator without a DX12 setup to run it on. That said, the previous code could not have worked here regardless: the
LegacySingleSrv*fields don't exist in 1.92, and the backend now allocates one descriptor per texture rather than one in total. I replaced them with the documentedSrvDescriptorAllocFn/SrvDescriptorFreeFncallbacks over a simple free list on the existing heap, following the pattern in ImGui'sexample_win32_directx12.It compiles, but someone with a D3D12 project (
samples/D3d12ImageBasicwould be the obvious test) should confirm it before this is relied on.How I verified
samples/ImGuibuilds and runs; verified interactively that the Tint Color and Border Color controls both affect the image as before.samples/,src/cinder/,include/cinder/andblocks/for remaining deprecated identifiers -- none found.