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

InputText callback data->BufDirty incorrectly changes internal buffer capacity, preventing further user input (repros in Demo window) #8168

Closed
Bizzarrus opened this issue Nov 19, 2024 · 3 comments

Comments

@Bizzarrus
Copy link

Version/Branch of Dear ImGui:

Version 1.91.3, Branch: docking

Back-ends:

Custom

Compiler, OS:

Windows 11 / MSVC

Full config/build information:

Dear ImGui 1.91.3 (19130)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=202004
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: IMGUI_DISABLE_OBSOLETE_KEYIO
define: IMGUI_DISABLE_WIN32_FUNCTIONS
define: IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
define: IMGUI_DISABLE_FILE_FUNCTIONS
define: IMGUI_DISABLE_DEFAULT_ALLOCATORS
define: _WIN32
define: _WIN64
define: _MSC_VER=1942
define: _MSVC_LANG=202004
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: Windows
io.BackendRendererName: ClockworkEngine
io.ConfigFlags: 0x00004481
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
 DpiEnableScaleViewports
io.ConfigViewportsNoTaskBarIcon
io.ConfigViewportsNoDecoration
io.ConfigDockingTransparentPayload
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 3440.00,1369.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

Details:

My Issue:

I'm trying to use ImGui::InputText with ImGuiInputTextFlags_CallbackEdit in order to remove invalid character sequences from the input buffer (for example, a double slash // should change to a single slash /). In order to do this, I call data->DeleteChars(...) on the callback data. (The issue reproduces any time data->BufDirty is set to true during this kind of callback)
This works on it's own. However, inside the ImGui::InputTextEx implementation, this leads to the call state->TextA.Size = state->CurLenA + 1;, which prevents the user from adding more characters afterwards (Clicking out of the text input and back in resets the state to the correct buffer size until the callback causes the issue to appear again).

The issue can also reproduced in the Demo window. Just navigate to Widgets -> Text Input -> Completion, History, Edit Callbacks and try to enter more than one letter into the Edit Text field. The same issue also happens in the Completion Text field after hitting the tab key.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

// Code from the Demo window

struct Funcs
{
    static int MyCallback(ImGuiInputTextCallbackData* data)
    {
        if (data->EventFlag == ImGuiInputTextFlags_CallbackEdit)
        {
            // Toggle casing of first character
            char c = data->Buf[0];
            if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) data->Buf[0] ^= 32;
            data->BufDirty = true;
        }
        return 0;
    }
};

static char buf3[64];
ImGui::InputText("Edit", buf3, 64, ImGuiInputTextFlags_CallbackEdit, Funcs::MyCallback);
// Try to type more than two letters, eg "ImGui", into the text input
@ocornut
Copy link
Owner

ocornut commented Nov 19, 2024

This was fixed in 1.91.5.

@Bizzarrus
Copy link
Author

Ah, thanks, I can confirm it's fixed in that version :) Sorry for the hassle, I just came back from a 3 weeks vacation and didn't see the new version :)

@ocornut
Copy link
Owner

ocornut commented Nov 20, 2024

For reference the main fix was 75f83de (followed by misc cleanups 82d0584, 63234f8), and the issue came to appear with 19accb1 for #7925

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