Skip to content

TextWrapped cannot display string larger than 3072 chars excluding null terminator #3466

@jpbrault

Description

@jpbrault

Version/Branch of Dear ImGui:

Version: 1.78 WIP
Branch: table

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_SDL.cpp + imgui_impl_opengl2.cpp
Compiler: GCC 9 / Clang 10
Operating System: Linux / Mac

My Issue/Question:

String larger than 3072 characters excluding null terminator are silently truncated when displayed by ImGui::TextWrapped.
In the following example, the last * character will no longer be displayed when the string size is increase past 3072.

#include <imgui.h>

#include <string>
#include <algorithm>

void showWindow()
{
  if ( ImGui::Begin( "Window", nullptr ) )
  {
    static int len = 3072;
    static std::string text;
    if ( ImGui::SliderInt("len", & len, 1, 4096 ) || text.empty() )
    {
      text.clear();
      text.reserve( len );
      for ( int i = 0; i < ( len - 1 ); ++ i )
      {
        text += 'A' + static_cast< char > ( i % 26 );
      }
      text += "*";
    }

    ImGui::TextWrapped( "%s", text.c_str() );
  }
  ImGui::End();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions