From 3a206718026ab88d8cf57dedaa48d55b756097cb Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 14 Jan 2015 13:01:53 +0000 Subject: [PATCH] Fixed logging to clipboard on architectures where va_list are modified by vsnprintf (fixed #112) --- imgui.cpp | 13 +++++++++++-- imgui.h | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index e9033ae5..9ab99289 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// ImGui library v1.20 +// ImGui library v1.21 wip // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' below for notes on how to setup ImGui in your codebase. // Get latest version at https://github.com/ocornut/imgui @@ -1180,9 +1180,18 @@ bool ImGuiTextFilter::PassFilter(const char* val) const //----------------------------------------------------------------------------- +// On some platform vsnprintf() takes va_list by reference and modifies it. +// va_copy is the 'correct' way to copy a va_list but Visual Studio prior to 2013 doesn't have it. +#ifndef va_copy +#define va_copy(dest, src) (dest = src) +#endif + // Helper: Text buffer for logging/accumulating text void ImGuiTextBuffer::appendv(const char* fmt, va_list args) { + va_list args_copy; + va_copy(args_copy, args); + int len = vsnprintf(NULL, 0, fmt, args); // FIXME-OPT: could do a first pass write attempt, likely successful on first pass. if (len <= 0) return; @@ -1191,7 +1200,7 @@ void ImGuiTextBuffer::appendv(const char* fmt, va_list args) Buf.reserve(Buf.capacity() * 2); Buf.resize(write_off + (size_t)len); - ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args); + ImFormatStringV(&Buf[write_off] - 1, (size_t)len+1, fmt, args_copy); } void ImGuiTextBuffer::append(const char* fmt, ...) diff --git a/imgui.h b/imgui.h index dc009ccc..0eaf64b6 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// ImGui library v1.20 +// ImGui library v1.21 wip // See .cpp file for commentary. // See ImGui::ShowTestWindow() for sample code. // Read 'Programmer guide' in .cpp for notes on how to setup ImGui in your codebase.