Browse Source

InputText: Fixed a crash on deactivating a ReadOnly buffer. (#6570, #6292, #4714)

This will be part of 1.89.7 Tagged relase.
ocornut 2 years ago
parent
commit
d4ddc46e77
3 changed files with 12 additions and 3 deletions
  1. 1 0
      docs/CHANGELOG.txt
  2. 1 1
      imgui.h
  3. 10 2
      imgui_widgets.cpp

+ 1 - 0
docs/CHANGELOG.txt

@@ -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.

+ 1 - 1
imgui.h

@@ -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
 
 /*

+ 10 - 2
imgui_widgets.cpp

@@ -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