Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui crashes (access violation) when clicking the '+' or '-' button of InputScalar #2844

Closed
Gliath opened this issue Oct 11, 2019 · 3 comments

Comments

@Gliath
Copy link

Gliath commented Oct 11, 2019

Dear ImGui 1.73 WIP (17203)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1923
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sfml
io.BackendRendererName: NULL
io.ConfigFlags: 0x00000041
 NavEnableKeyboard
 DockingEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMemoryCompactTimer = 60.0f
io.BackendFlags: 0x00000007
 HasGamepad
 HasMouseCursors
 HasSetMousePos
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

ImGui crashes when I click on the + or - button of a InputScalar:

I want to be able to change some value of an object.
When I tested the + and/or - (on various datatypes), it crashes.
The gif shows the implementation for my project, but I tested with a minimal code as well and the result is the same.

Screenshots/Video

Editing a gif

Crash after clicking the '+' or '-' button

Code used (minimized):

ImGui::Begin("Example Bug");
static int8_t testingBugValue = 2;
int8_t bugValue = testingBugValue;
ImGuiInputTextFlags flags = ImGuiInputTextFlags_None;
const char* format = (flags & ImGuiInputTextFlags_CharsHexadecimal) ? "%08X" : "%d";
ImGui::InputScalar("Byte", ImGuiDataType_S8, &bugValue, (void*) 1, (void*) 64, format, flags);
testingBugValue = bugValue;
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Oct 11, 2019

If you look at the crash you'll notice it is trying to dereference the step step_fast pointers to get the value. You are giving it 1 and 64 as pointers so dereferencing that would crash. You should pass pointer to an address hold the values.

Look at imgui_demo.cpp for how to use InputScalar, under Widgets->Data Types the coments are explaning how it works and why it works this way.

@ocornut ocornut closed this as completed Oct 11, 2019
@ocornut
Copy link
Owner

ocornut commented Oct 11, 2019

In other words you can use:

static int8_t step = 1;
static int8_t step_fast = 64;
ImGui::InputScalar("Byte", ImGuiDataType_S8, &bugValue, &step, &step_fast, format, flags);

But I recommend reading the comments to understand why it works this way.

I will now make a change to the function prototype to add p_ prefix to those arguments to hopefully clarify their use.

ocornut added a commit that referenced this issue Oct 11, 2019
…hat are pointers to the datato clarify how they are used, and more comments redirecting to the demo code. (#2844)
@Gliath
Copy link
Author

Gliath commented Oct 11, 2019

Thank you for the clarification.
I didn't think of the possibility of a de-referencing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants