Skip to content

Commit

Permalink
InputText: Fixed a crash on deactivating a ReadOnly buffer. (#6570, #…
Browse files Browse the repository at this point in the history
…6292, #4714)

This will be part of 1.89.7 Tagged relase.
  • Loading branch information
ocornut committed Jul 4, 2023
1 parent 40aac58 commit d4ddc46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ Other changes:
- CollapsingHeader/TreeNode: Fixed text padding when using _Framed+_Leaf flags. (#6549) [@BobbyAnguelov]
- InputText: Fixed not returning true when buffer is cleared while using the
ImGuiInputTextFlags_EscapeClearsAll flag. (#5688, #2620)
- InputText: Fixed a crash on deactivating a ReadOnly buffer. (#6570, #6292, #4714)
- InputText: ImGuiInputTextCallbackData::InsertChars() accept (NULL,NULL) range, in order to conform
to common idioms (e.g. passing .data(), .data() + .size() from a null string). (#6565, #6566, #3615)
- Combo: Made simple/legacy Combo() function not returns true when picking already selected item.
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.89.7"
#define IMGUI_VERSION_NUM 18970
#define IMGUI_VERSION_NUM 18971
#define IMGUI_HAS_TABLE

/*
Expand Down
12 changes: 10 additions & 2 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4052,8 +4052,16 @@ void ImGui::InputTextDeactivateHook(ImGuiID id)
if (id == 0 || state->ID != id)
return;
g.InputTextDeactivatedState.ID = state->ID;
g.InputTextDeactivatedState.TextA.resize(state->CurLenA + 1);
memcpy(g.InputTextDeactivatedState.TextA.Data, state->TextA.Data ? state->TextA.Data : "", state->CurLenA + 1);
if (state->Flags & ImGuiInputTextFlags_ReadOnly)
{
g.InputTextDeactivatedState.TextA.resize(0); // In theory this data won't be used, but clear to be neat.
}
else
{
IM_ASSERT(state->TextA.Data != 0);
g.InputTextDeactivatedState.TextA.resize(state->CurLenA + 1);
memcpy(g.InputTextDeactivatedState.TextA.Data, state->TextA.Data, state->CurLenA + 1);
}
}

// Edit a string of text
Expand Down

0 comments on commit d4ddc46

Please sign in to comment.