Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling ASAN produces alignment warning when hovering over table headers #3872

Closed
justSomeFella opened this issue Mar 3, 2021 · 2 comments

Comments

@justSomeFella
Copy link

Dear ImGui 1.82 WIP (18101)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=201402
define: __linux__
define: __GNUC__=9
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000000
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000000E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.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.00

Version/Branch of Dear ImGui:

Version: 1.8.2
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler:
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

Operating System: Ubuntu 20.04.2 LTS

My Issue/Question:

Hello!

I was compiling imgui with address sanitizer in a separate project and I noticed some warnings spitting out to the console when using the tables branch and hovering over a header. I was able to produce a MVE by adding the address sanitizer flags to the example 'example_glfw_opengl3' Makefile in the imgui repo.

Created a fork and branch here:
https://github.com/justSomeFella/imgui/tree/bug_report/alignment_warning

But will include relevant output in this issue as well.

Screenshots/Video
Log output included in the branch above, but included here as well

./example_glfw_opengl3 
../../imgui_internal.h:534:117: runtime error: reference binding to misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^ 
../../imgui_tables.cpp:1553:28: runtime error: member access within misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^ 
../../imgui_tables.cpp:1554:27: runtime error: member access within misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 42  96 fa cc 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^ 
../../imgui_tables.cpp:1725:77: runtime error: member access within misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 42  96 fa cc 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^ 
../../imgui_tables.cpp:1726:76: runtime error: member access within misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 42  96 fa cc 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00
             ^ 
../../imgui_tables.cpp:1730:48: runtime error: member access within misaligned address 0x61800001335f for type 'struct ImGuiTableCellData', which requires 4 byte alignment
0x61800001335f: note: pointer points here
 03 04 05 06 42  96 fa cc 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00

This happens when the steps

1. modified the Makefile to include -fsanitize=address,undefined
2. run the example_glfw_opengl3 binary
3. hover over any column heading in a table with the cursor
    for example (In the demo window) 
        Tables & columns -> Horizontal Scrolling -> Line #

I noticed it seems to happen once, as in I cannot get it spitting out the error again if I hover over the same table header.

Standalone, minimal, complete and verifiable example:
modify the CXX global flags section to include in examples/example_glfw_opengl3/Makefile

CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -fsanitize=address,undefined
CXXFLAGS += -g -Wall -Wformat
LDFLAGS = -fsanitize=address,undefined
LIBS =

Then run the example_glfw_opengl3 binary.

I did try crawling through the issues/todos below, but couldn't find anything specific to this output
#3740 (comment)

If there is any other output or information I can provide please feel free to let me know. The library has been great to use thus far, thank you for working on it!

ocornut added a commit that referenced this issue Mar 4, 2021
…eBgTarget_CellBg). (#3872)

ImSpanAllocator: Support for alignment.
@ocornut
Copy link
Owner

ocornut commented Mar 4, 2021

Thank you very much for this report.
This is now fixed by d8c88bd

And you gave us the idea to enable ASAN in our CI run for regression tests (covering a good portion of the codebase)!

@ocornut ocornut closed this as completed Mar 4, 2021
@justSomeFella
Copy link
Author

Thank you so much!

Cheers

duddel added a commit to duddel/imgui that referenced this issue Mar 4, 2021
commit ee643b2
Author: ocornut <[email protected]>
Date:   Thu Mar 4 19:59:59 2021 +0100

    IsItemHovered(): fixed return value false positive when used after EndChild(), EndGroup() or widgets using either... (ocornut#3851, ocornut#1370)

    ...when the hovered location is located within a child window, e.g. InputTextMultiline().
    This is intended to have no side effects, but brace yourself for the possible comeback..
    This essentially makes IsItemHovered() not accept hover from child windows, but EndChild/EndGroup are forwarded.
    More or less should fix/revert c76f014 which was a revert of 344d48b

commit b53b8f5
Author: Rokas Kupstys <[email protected]>
Date:   Thu Mar 4 16:27:43 2021 +0200

    Demo: Use correct string formats on non-windows platforms.

    (amended)

commit 3e6dfd3
Author: ocornut <[email protected]>
Date:   Thu Mar 4 13:37:14 2021 +0100

    ImDrawList: AddImageRounded() compare texid from cmdheader as with other functions. + Made the ImGuiMemAllocFunc / ImGuiMemFreeFunc consistent with our other typedefs (ocornut#3836)

commit 8dd692c
Author: ocornut <[email protected]>
Date:   Thu Mar 4 11:03:40 2021 +0100

    Android: Amend backend and examples with minor consistency tweaks. (ocornut#3446)

commit fb85c03
Author: duddel <[email protected]>
Date:   Thu Mar 4 10:35:44 2021 +0100

    Add Android backend and example (ocornut#3446)

commit d8c88bd
Author: ocornut <[email protected]>
Date:   Thu Mar 4 09:52:00 2021 +0100

    Tables: Fixed unaligned accesses when using TableSetBgColor(ImGuiTableBgTarget_CellBg). (ocornut#3872)

    ImSpanAllocator: Support for alignment.

commit 1ddaff8
Author: ocornut <[email protected]>
Date:   Wed Mar 3 18:45:52 2021 +0100

    Demo: Tweak inputs display.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants