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

Demo window crash when clicking "Show Item Picker" #7146

Closed
f9x0 opened this issue Dec 18, 2023 · 2 comments
Closed

Demo window crash when clicking "Show Item Picker" #7146

f9x0 opened this issue Dec 18, 2023 · 2 comments

Comments

@f9x0
Copy link

f9x0 commented Dec 18, 2023

Dear ImGui 1.89.7 (18970)
--------------------------------
sizeof(size_t): 4, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _MSC_VER=1900
define: _MSVC_LANG=201402
--------------------------------
io.BackendPlatformName: imgui_impl_win32
io.BackendRendererName: imgui_impl_dx11
io.ConfigFlags: 0x00000003
 NavEnableKeyboard
 NavEnableGamepad
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: 1264.00,749.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: 1.89.7-1.90
Branch: everything I tried
I tried Demo, all backend. Compiled 1.90 with different options. I got this bug everywhere.

Operating System: Windows

When I launch the demo window.
When going to Tools - Metrics/Debugger - Tools
I click "Show Item Picker" and if I click again.
This will crash the application. The crash also occurs if: After checking the "Show Item Picker" checkbox. I'll put a tick in the checkbox somewhere else.
It crashes in absolutely everything I tried from 1.87.9 (demo) to 1.90

@GamingMinds-DanielC
Copy link
Contributor

If you hover the question mark, it says:
"Will call the IM_DEBUG_BREAK() macro to break in debugger.
Warning: If you don't have a debugger attached, this will probably crash."

This is not actually a crash, the help text just says that because it is indistinguishable from one if you are not debugging. That is basically the intended function. You activate the picker, then click the item you want to inspect, then ImGui halts program execution when the application commits that item the next time. Within the debugger, you can then step through the instructions, inspect local variables and so on. Without a debugger attached... well, maybe that tool could be deactivated if no debugger is attached, but I don't know how to detect that in a platform agnostic way.

@ocornut
Copy link
Owner

ocornut commented Dec 19, 2023

Closing as answered. Thank you Daniel.
This is also the reason why the item picker is not directly in Demo->Tools.
Linking to #2673

Without a debugger attached... well, maybe that tool could be deactivated if no debugger is attached, but I don't know how to detect that in a platform agnostic way.

This is how imgui_test_engine does it:
https://github.com/ocornut/imgui_test_engine/blob/main/imgui_test_engine/imgui_te_utils.cpp#L976C1-L1001C2

bool    ImOsIsDebuggerPresent()
{
#ifdef _WIN32
    return ::IsDebuggerPresent() != 0;
#elif defined(__linux__)
    int debugger_pid = 0;
    char buf[2048];                                 // TracerPid is located near the start of the file. If end of the buffer gets cut off thats fine.
    FILE* fp = fopen("/proc/self/status", "rb");    // Can not use ImFileLoadToMemory because size detection of /proc/self/status would fail.
    if (fp == NULL)
        return false;
    fread(buf, 1, IM_ARRAYSIZE(buf), fp);
    fclose(fp);
    buf[IM_ARRAYSIZE(buf) - 1] = 0;
    if (char* tracer_pid = strstr(buf, "TracerPid:"))
    {
        tracer_pid += 10;   // Skip label
        while (isspace(*tracer_pid))
            tracer_pid++;
        debugger_pid = atoi(tracer_pid);
    }
    return debugger_pid != 0;
#else
    // FIXME
    return false;
#endif
}

One problem we have is that this is one of the most useful Dear ImGui debug tools, and yet it is largely under-discovered by people. If it required an opt-in IsDebuggerAttached type of signal from the user application, it would dramatically reduce it's discoverability and I think would be a net negative. So it's always on but somehow hidden in Metrics.

I suppose we should add such application-fed signal, and wire it to "Demo->Tools->Item Picker" with the item greyed with a message of how to enable + message stating it can always be accessed from Metrics.

@ocornut ocornut closed this as completed Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants