ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.41k stars 10.33k forks source link

Assert when using font awesome Icons #8070

Open WennerChen opened 1 month ago

WennerChen commented 1 month ago

Version/Branch of Dear ImGui:

Version 1.91.3 and version 1.90.9

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx11.cpp

Compiler, OS:

Windows 10 + GCC-8.5.0 with MinGW-w64-8.0.3

Full config/build information:

g++.exe -c main.cpp -o main.o -O2 -pipe

windres.exe -i imgui-fontawesome-test_private.rc --input-format=rc -o imgui-fontawesome-test_private.res -O coff

g++.exe imgui/imgui_impl_win32.o imgui/imgui.o imgui/imgui_demo.o imgui/imgui_draw.o main.o imgui/imgui_tables.o imgui/imgui_impl_dx11.o imgui/imgui_widgets.o imgui-fontawesome-test_private.res -o imgui-fontawesome-test.exe -s -ld3d11 -ld3dcompiler -ldxgi -lgdi32 -ldwmapi -static

Details:

When I tried to compile caiocinel/imgui-fontawesome-example using GCC-8.5.0 with MinGW-w64-8.0.3 on Windows 10, the application exited with an assertion in file imgui/imstb_truetype.h, line 3160. It's fine with MSVC-2015.

Screenshots/Video:

Assertion failed: dy >= 0, file imgui/imstb_truetype.h, line 3160


Process exited after 2.554 seconds with return value 3 (562.5 ms cpu time, 62744 KB mem used).

Press ANY key to exit...

Minimal, Complete and Verifiable Example code:

static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
    ImFontConfig icons_config;
    icons_config.MergeMode = true; // Merge icon font to the previous font if you want to have both icons and text
    //io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\Verdana.ttf", 18.0f);
    ImFont *font = io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\msyh.ttc", 18.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull());

    io.Fonts->AddFontFromMemoryCompressedTTF(FA_compressed_data, FA_compressed_size, 12.0f, &icons_config, icons_ranges);
ocornut commented 1 month ago

Hello, Can you verify that this happens when loading the .ttf file from the file-system with AddFontFromFileTTF()?

WennerChen commented 1 month ago

Hello, Can you verify that this happens when loading the .ttf file from the file-system with AddFontFromFileTTF()?

Yes, same thing happens when I use the code shown as bellow:

io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, 18.0f, &icons_config, icons_ranges);

Everything is fine with MSVC2015, but the application crashes and shows assertion with MinGW

sonoro1234 commented 1 month ago

I get the same assert. It depends on icons_ranges value (maximun 0xf06d for size 16 without error) and also on font size (not for size 13 for example). Does not happen on a mingw-w64 64bits build but happens with 32 bits build Does not happen in 1.91.3 but happens in 1.91.4 (docking)

Could be related to ImTextureID changing from void* to ImU64?

sonoro1234 commented 1 month ago

My case is for impl_opengl3 (when calling ImGui_ImplOpenGL3_CreateDeviceObjects) Only happening in Release or RelWithDebInfo but not in Debug build for 32bit with mingw-w64

ocornut commented 1 month ago

Please provide exact compilation and linking flags for dear imgui. Neither of you provided them.

sonoro1234 commented 1 month ago

It is a CMake build from https://github.com/sonoro1234/LuaJIT-ImGui/blob/docking_inter/CMakeLists.txt

comand

cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DLUAJIT_BIN="c:/anima" -DSDL_PATH="C:\LuaGL\gitsources\BUILDS\SDL2\install" -DSDL3_PATH="C:\LuaGL\gitsources\BUILDS\SDL3\install" -DGLFW_PATH="C:\LuaGL\gitsources\BUILDS\GLFW\install"  ../../anima/LuaJIT-imgui

Where the only relevant flag is -DCMAKE_BUILD_TYPE=Release (or RelWithDebInfo) and compiler is mingw-w64 for 32bits

I will try to get a simpler reproducer with example_glfw_opengl3

WennerChen commented 1 month ago

My compilation is shown as below:

g++.exe -c imgui/imgui_demo.cpp -o imgui/imgui_demo.o   -O2 -pipe 

g++.exe -c imgui/imgui_tables.cpp -o imgui/imgui_tables.o   -O2 -pipe 

g++.exe -c imgui/imgui_impl_win32.cpp -o imgui/imgui_impl_win32.o   -O2 -pipe 

g++.exe -c imgui/imgui_widgets.cpp -o imgui/imgui_widgets.o   -O2 -pipe 

g++.exe -c imgui/imgui_impl_dx11.cpp -o imgui/imgui_impl_dx11.o   -O2 -pipe 

g++.exe -c imgui/imgui_draw.cpp -o imgui/imgui_draw.o   -O2 -pipe 

g++.exe -c main.cpp -o main.o   -O2 -pipe 

g++.exe -c imgui/imgui.cpp -o imgui/imgui.o   -O2 -pipe 

windres.exe -i imgui-fontawesome-test_private.rc --input-format=rc -o imgui-fontawesome-test_private.res -O coff  

g++.exe imgui/imgui_demo.o imgui/imgui_tables.o imgui/imgui_impl_win32.o imgui/imgui_widgets.o imgui/imgui_impl_dx11.o imgui/imgui_draw.o main.o imgui/imgui.o imgui-fontawesome-test_private.res -o imgui-fontawesome-test.exe -s -ld3d11 -ld3dcompiler -ldxgi -lgdi32 -ldwmapi -static

My case is for 32bit with mingw-w64, and I have'd try this for 64bit.

sonoro1234 commented 1 month ago

https://github.com/sonoro1234/imgui/tree/stbtt_assert is a branch where we can go to example_glfw_opengl3/build edit init_cmake.bat to make sure mingw-w64 and cmake are on your PATH and then run:

init_cmake mingw32-make install example_glfw_opengl3.exe

mingw-w64 can be found on https://github.com/niXman/mingw-builds-binaries/releases

i686-14.2.0-release-posix-dwarf-msvcrt-rt_v12-rev0.7z is for 32bits