Skip to content

Non-working sliders when iterating through vector #654

@mruegenberg

Description

@mruegenberg

I've found a pretty weird behavior where I can't influence slider values (I can drag, but the slider always snaps back to the original value).

Basically, the following fails:

std::vector<float> foos;
foos.push_back(0.3);
// ...
for(float s : foos) {
    ImGui::SliderFloat("float x", &s, 0.0f, 1.0f);
}

but this works:

std::vector<float> foos;
foos.push_back(0.3);
// ...
for(float &s : foos) {
    ImGui::SliderFloat("float x", &s, 0.0f, 1.0f);
}

I'm not sure if this is expected behavior and/or can even be reproduced on other systems (I compiled with g++ 6.1.1), but I'd be interested in the reasons for the failure.

In the attachment, there is a full main.cpp (as a txt, because Github only allows those)
main.cpp.txt
which can be dragged into opengl_example to reproduce the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions