mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-14 19:04:44 +00:00
Silent NULL reference when merging into an invalid ImFont. #6446
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#6446
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Version: 1.89.6 WIP (18954)
Branch: docking
Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
I am currently writing a wrapper on top of
dear_bindingsso please forgive any c++ syntax errors as I have translated code from C to C++. Silent NULL references are hard to deal with in binding languages :(It's possible to crash ImGui (with assertions on) using the code below with regards to merging fonts.
The fonts themselves don't matter, just that these conditions are met:
I've chosen to use a Math symbol font to show this.
Excerpt from
imgui_draw.cppImFontAtlasBuildWithStbTruetypeInside
ImFont::AddGlyphthe line withContainerAtlas->TexGlyphPaddingcauses the crash sinceContainerAtlasis NULL.ContainerAtlaswould normally be set byImFontAtlasBuildSetupFont()(Shown above) but:ImFontAtlasBuildSetupFont()is never run)ImFontAtlasBuildSetupFont()), the resulting font does not have a valid ContainerAtlas, resulting in the NULL access insideAddGlyph().You can see this by uncommenting
builder.AddText("Some valid chars Ω");. Then the crash doesn't happen because Font A is valid. Otherwise trying to use Font A (without a merge) would normally be caught byIM_ASSERT(font && font->IsLoaded());insideimgui.cpp.I think I would be good to
IM_ASSERTto check ifContainerAtlasis valid, just in case the user tries merging two fonts like this.My suggestion is to add the following inside
ImFont::AddGlyphOr something similar to indicate to the user that they have made a mistake.
Thanks for reporting this in details and carefully. I confirmed the edge case and push a fix
08145bc.Even though it is a little odd, it seems valid and instead of asserting I let it run by removing the
(src_tmp.GlyphsCount == 0)check.Pleased to hear that dear_bindings may be useful to you!
For reference the repro in a version that compiles in C++:
That's great. Solved at the source. I'll make sure to spin up a working c++ example in future.
dear_bindings is S tier.