imgui: ImGui::InputText freezes in v1.87+ in a Win32 IME ImmAssociateContextEx() call

Version/Branch of Dear ImGui:

Version: v1.88 Branch: https://github.com/Microsoft/vcpkg/blob/master/ports/imgui/portfile.cmake

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp Compiler: MSVC Operating System: Windows 11 Pro

My Issue/Question:

I’m using ImGui::InputText() to create text fields. Since v.187 of Dear ImGui clicking into text fields freezes the entire application (no crash but “stopped responding”). The bug does not occur with v1.86 and the bug still occurs in v1.88.

Standalone, minimal, complete and verifiable example:

std::string input_text;
ImGui::Begin("Example Bug");
ImGui::InputText("My text field", &input_text);
ImGui::End();

I researched but didn’t find a clear solution or workaround (besides downgrading to v1.86). I believe my issue is similar to https://github.com/ocornut/imgui/issues/4972 and https://github.com/ocornut/imgui/issues/5264. How exactly would you debug into ImGui::InputText() getting stuck if needed? ImGui::InputText() takes me to the imgui_stdlib.h file and not the .cpp file and input texts are probably handled somewhere else. What exactly changed between those versions which could cause this regression? Thanks in advance for taking a look into this.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 23 (13 by maintainers)

Commits related to this issue

Most upvoted comments

@ocornut I could reproduce it with a pretty simple hello world example. Now I’m a bit stuck regarding what could still cause this issue. Please take a look at my repository: https://github.com/BullyWiiPlaza/ImGuiFreezingTest I invited you as collaborator, please accept the invite and you can access this private repository. All instructions are provided in the README.

  1. Yes, I’m running with a debugger attached. However, it does not matter if I’m using a debugger or not, the bug always occurs. Users running the release build also report this issue and they obviously don’t have a debugger attached.
  2. Not applicable, there is no symbols loading going on when it freezes. Generally symbols loading would take a few seconds and in this case, the process never unfreezes itself, even after minutes of waiting.
  3. Yes, this fixes the bug and it no longer freezes.
  4. This does not make a difference.
  5. I did not try since 3. worked fine.

Thanks for the feedback.

Based on the multiple reports and the fact we did make changes to Win32 IME code in 1.87, I am assuming we do have an issue but I would like to understand if it is tied to debugger loading symbols or something else.

How exactly would you debug into ImGui::InputText() getting stuck if needed?

If something appears stuck, you first want to break in the debugger to find where.

What exactly changed between those versions which could cause this regression?

Answer is in the changelog:

- Platform IME: moved io.ImeWindowHandle to GetMainViewport()->PlatformHandleRaw.
- Platform IME: add ImGuiPlatformImeData::WantVisible, hide IME composition window when not used. (#2589) [@actboy168]
- Platform IME: add ImGuiPlatformImeData::InputLineHeight. (#3113) [@liuliu]
- Platform IME: [windows] call ImmSetCandidateWindow() to position candidate window.

Diffing between 1.86 and 1.87, the important related changes here are that we want from:

static void ImeSetInputScreenPosFn_DefaultImpl(int x, int y)
{
    // Notify OS Input Method Editor of text input position
    ImGuiIO& io = ImGui::GetIO();
    if (HWND hwnd = (HWND)io.ImeWindowHandle)
        if (HIMC himc = ::ImmGetContext(hwnd))
        {
            COMPOSITIONFORM cf;
            cf.ptCurrentPos.x = x;
            cf.ptCurrentPos.y = y;
            cf.dwStyle = CFS_FORCE_POSITION;
            ::ImmSetCompositionWindow(himc, &cf);
            ::ImmReleaseContext(hwnd, himc);
        }
}

to

static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport* viewport, ImGuiPlatformImeData* data)
{
    // Notify OS Input Method Editor of text input position
    HWND hwnd = (HWND)viewport->PlatformHandleRaw;
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
    if (hwnd == 0)
        hwnd = (HWND)ImGui::GetIO().ImeWindowHandle;
#endif
    if (hwnd == 0)
        return;

    ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0);

    if (HIMC himc = ::ImmGetContext(hwnd))
    {
        COMPOSITIONFORM composition_form = {};
        composition_form.ptCurrentPos.x = (LONG)data->InputPos.x;
        composition_form.ptCurrentPos.y = (LONG)data->InputPos.y;
        composition_form.dwStyle = CFS_FORCE_POSITION;
        ::ImmSetCompositionWindow(himc, &composition_form);
        CANDIDATEFORM candidate_form = {};
        candidate_form.dwStyle = CFS_CANDIDATEPOS;
        candidate_form.ptCurrentPos.x = (LONG)data->InputPos.x;
        candidate_form.ptCurrentPos.y = (LONG)data->InputPos.y;
        ::ImmSetCandidateWindow(himc, &candidate_form);
        ::ImmReleaseContext(hwnd, himc);
    }
}

If you want to help I would need you to very precisely answer the following questions, one by one:

  1. Are you running with a debugger attached? Does it makes any difference if you have a debugger attached or not?
  2. If the “freeze” only happens with a debugger attached: have if you tried waiting for several minutes? Does Visual Studio shows a “loading symbol” window, if so, can you press ESC and does it resume the application?
  3. Try commenting the line ::ImmAssociateContextEx(hwnd, NULL, data->WantVisible ? IACE_DEFAULT : 0);. Does it makes a difference?
  4. Try commenting only the line ::ImmSetCandidateWindow(himc, &candidate_form);. Does it makes a difference?
  5. Try commenting both lines above. Does it makes a difference?

Thank you very much!