-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Fonts: Renderer_TextureMaxXXXX Is Not Honored When Font Texture Grows #8758
Description
Version/Branch of Dear ImGui:
Version: 1.92.1 WIP, Branch: docking
Back-ends:
Custom (DirectDraw)
Compiler, OS:
Windows 11 + VSCode / MSVC 2022 via clang + ninja
Full config/build information:
Dear ImGui 1.92.1 WIP (19201)
--------------------------------
sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: _WIN32
define: _MSC_VER=1943
define: _MSVC_LANG=202400
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_atomic_win32
io.BackendRendererName: imgui_atomic_ddraw
io.ConfigFlags: 0x00000080
DockingEnable
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDecoration
io.ConfigViewportsNoDefaultParent
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00000C1E
HasMouseCursors
HasSetMousePos
PlatformHasViewports
HasMouseHoveredViewport
RendererHasVtxOffset
RendererHasTextures
--------------------------------
io.Fonts: 4 fonts, Flags: 0x00000000, TexSize: 512,128
io.Fonts->FontLoaderName: stb_truetype
io.DisplaySize: 1920.00,1080.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00Details:
I am currently testing out the newest font changes made to ImGui as several of my projects that make use of ImGui have seen a handful of user bug reports of various font problems in the past. While I am currently making use of a custom backend to implement ImGui within DirectDraw, I have followed the changes made to the Direct3D 9 backend to implement the new texture handling.
Tonight, I have managed to crash ImGui with an issue I don't think should be happening. In the Direct3D 9 backend, two new settings have been added for the rendering platform to limit the size of the textures that will be used by ImGui, which are Renderer_TextureMaxWidth and Renderer_TextureMaxHeight. It does not appear that the font system is honoring these settings / limits properly.
As a quick means to reproduce this problem, the Direct3D 9 example can be edited to just add a few more fonts being loaded then a few basic interactions with the ImGui demo will cause the crash.
Here are some reproduction steps using the d3d9 example:
- Set the platform texture size settings to something expected like:
4096 x 4096 - Add several additional fonts to be loaded, set to size:
16.0f(I am able to reproduce this with 4 fonts total.)- Agave (with FontAwesome merged into it), Arial, Bell, Bookos
- Ensure the example has the demo window showing to be able to access the style editor.
Once compiled and running, in the app you can do the following:
- Open the
Style Editor. (Demo window -> Tools -> Style Editor) - Choose the
Fontstab. - Scroll down to the
Font Listsection. (There should be 4 fonts showing.)
This next set of steps to cause the crash should be repeated for each font that is listed, starting with the already set default font:
- Slide the
FontSizeBasesetting value between the lowest and highest value a few times. - Slide the
FontScaleMainsetting value between the lowest and highest value a few times. - Slide the
FontScaleDpisetting value between the lowest and highest value a few times. - Repeat these steps with the
FontSizeBasesetting at multiple sizes to cause multiple sizes of the fonts data to be cached, filling up the texture some. - In the
Font Listsection, go to the next font in the list, expand its info and click theSet as Defaultbutton. - With the new font set as default, repeat this sections steps.
Doing this will cause the texture to continue to grow as it caches all the different sizes/scales of each font. Eventually, for me ImGui will crash here:
Line 2474 in 3ec62df
| memset(Pixels, 0, Width * Height * BytesPerPixel); |
If you are currently in debug mode, the assert should be hit because the allocation will fail, or the memset call will error because Pixels is null. Viewing the arguments of the call shows that ImGui is attempting to create a new texture with the size of 8192 x 8192 which exceeds the Renderer_TextureMaxXXXX settings we set. In my case, this is trying to call IM_ALLOC as: 8192 x 8192 x 4
Screenshots/Video:
Debugging via Visual Studio as VSCode debugging is terrible.
Minimal, Complete and Verifiable Example code:
Usage of the Direct3D 9 example app should suffice for this. Just add loading a few extra fonts as mentioned above.
