epezent / implot

Immediate Mode Plotting
MIT License
4.55k stars 503 forks source link

SetNextAxesLimits() not updating/changing plot #494

Closed denniskb closed 1 year ago

denniskb commented 1 year ago

My code:

ImGui::SliderInt("X axis", &X, 1, 50);
ImPlot::SetNextAxesLimits(0, X, 0, 1);
ImPlot::BeginPlot("...");
ImPlot::PlotLine(...);
ImPlot::EndPlot();

The axes limits do not update as I move the slider, they remain at the initial value of X.

denniskb commented 1 year ago

Also, adding this code to an existing application with an existing imgui.ini file works fine. But when I delete imgui.ini, the app crashes with

Assertion failed: ((gp.CurrentPlot != nullptr) && "PlotX() needs to be called between BeginPlot() and EndPlot()!"), function BeginItem, file implot_items.cpp, line 397.
denniskb commented 1 year ago

The first issue was resolved by passing ImPlotCond_Always. The second one by wrapping the ImPlot::BeginPlot() call inside an if.