mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-16 19:11:13 +00:00
Segmentation fault when logging to clipboard #112
Labels
No labels
accidentally closed
android
backends
bug
building
clipper
coloredit
color spaces
cplusplus
data types
demo
disabled
doc
docking
dpi
drag drop
drawing/drawlist
dropped
dx12
enhancement
focus
font/text
gallery
help wanted
idle/power saving
ime
in progress
inputs
inputtext
internals
label/id and id stack
language bindings
layout
linux/bsd
menus
multi-contexts
multi-threading
multi-viewports
nav
news/info
opengl
optimization
osx/ios
overlap
plot/graph
popups
question
scrolling
selection
settings
sliders/drags
style
tables/columns
tabs
test wanted
tools
tooltips
tree
tricks & tips
useful widgets
vulkan
web
window pos/depth
window sizing
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ocornut/imgui#112
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I'm trying to log my Console output (a bunch of TextUnformatted) to the clipboard. Unfortunately, I get a segmentation fault in vsnprintf at imgui.cpp:587 (referring to imgui v1.20).
I've replaced my console output with "Test". It still segfaults.
Stepping up some frames in the debugger, I can see the faulting call starts out as TextUnformatted, going to RenderText at imgui.cpp:3294, then LogText at imgui.cpp:1912, to LogText on imgui.cpp:1858, to appendv at imgui.cpp:1815, to ImFormatStringV at imgui.cpp:1194.
Unfortunately I can't find the source of the problem.
Could you provide a repro or at least paste in the code you are using?
I did a few tests and couldn't reproduce the issue.
Of course, the complete Console code can be found here. Logging is enabled in Line 105, the TextUnformatted is in Line 128, and logging ends on Line 132. It works with LogToFile and LogToTTY, but not LogToClipboard.
Hmm, well assuming all your "entry.text.c_str()" values are non-null and the string zero-terminated the user code sounds right. I can't find an issue with appendv() but maybe vsnprintf() doesn't behave as I expected on some systems with a NULL parameter and 0 size as input (I am measuring it to measure the output buffer requirement). Which system/compiler are you using?
In appendv() could you retrieve the local variables from a debugger and dump them here?
len, write_off, Buf.size, Buf.capacity, and fmt.
I'm on Mac OS X 10.10.1, my compiler identifies as
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn).I've just added two checks, so I can confirm all the strings are neither NULL nor zero length.
And here are the dumped values:
To be honest, I would not be surprised if this is some strange bug in vsnprintf on Macs... :)
What are the parameter passed to
ImGui::LogText(STR_NEWLINE "%_s%._s", tree_depth*4, "", char_count, text_remaining);
tree_depth, char_count, text_remaining ?
Thanks again!
The length changed - I think I was still printing only "Test" in the first dump, now it's the regular console text. So here it is:
And the arguments to LogText:
And no problem. I really hope it does not turn out to be a problem in my code, so I just wasted your time... 😄
E-mailing you :)
Probably that
http://www.bailopan.net/blog/?p=30
That's it! Quick platform specific fix from ocornut for anyone else affected:
Unfortunately va_copy doesn't work with Visual Studio pre 2013 and god-knows-what compiler.
I am assuming that va_copy is macro to define it as a simple assignment if macro doesn't exist.
That will break if on some system va_copy exists and isn't a macro and isn't a simple assignment. Most code on the internet seems to assume that va_copy is always a macro if it exists.