Skip to content

Commit bfc1e09

Browse files
committed
Fix bug and possibility of misuse in Demo_SubplotsSizing
1 parent 3c92593 commit bfc1e09

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

implot_demo.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ void Demo_SubplotsSizing() {
12721272
static int cols = 3;
12731273
ImGui::SliderInt("Rows",&rows,1,5);
12741274
ImGui::SliderInt("Cols",&cols,1,5);
1275+
if (rows < 1 || cols < 1) {
1276+
ImGui::TextColored(ImVec4(1,0,0,1), "Nice try, but the number of rows and columns must be greater than 0!");
1277+
return;
1278+
}
12751279
static float rratios[] = {5,1,1,1,1,1};
12761280
static float cratios[] = {5,1,1,1,1,1};
12771281
ImGui::DragScalarN("Row Ratios",ImGuiDataType_Float,rratios,rows,0.01f,nullptr);
@@ -1281,7 +1285,9 @@ void Demo_SubplotsSizing() {
12811285
if (ImPlot::BeginPlot("",ImVec2(),ImPlotFlags_NoLegend)) {
12821286
ImPlot::SetupAxes(nullptr,nullptr,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations);
12831287
float fi = 0.01f * (i+1);
1284-
ImPlot::SetNextLineStyle(SampleColormap((float)i/(float)(rows*cols-1),ImPlotColormap_Jet));
1288+
if (rows*cols > 1) {
1289+
ImPlot::SetNextLineStyle(SampleColormap((float)i/(float)(rows*cols-1),ImPlotColormap_Jet));
1290+
}
12851291
ImPlot::PlotLineG("data",SinewaveGetter,&fi,1000);
12861292
ImPlot::EndPlot();
12871293
}

0 commit comments

Comments
 (0)