alandefreitas / matplotplusplus

Matplot++: A C++ Graphics Library for Data Visualization 📊🗾
https://alandefreitas.github.io/matplotplusplus/
MIT License
4.11k stars 313 forks source link

example_parallelplot_1 crashes #325

Open jschueller opened 1 year ago

jschueller commented 1 year ago

Bug category

Describe the bug the parallelplot example "example_parallelplot_1" crashes in 1.1.0 & master at https://github.com/alandefreitas/matplotplusplus/blob/master/source/matplot/axes_objects/parallel_lines.cpp#L181 (it tries to access an element of a std::vector at an invalid index)

Steps to Reproduce

# Your steps go here
mkdir build
cd build
cmake  -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS="-Wall -D_GLIBCXX_ASSERTIONS"  ..
gdb ./examples/data_distribution/parallelplot/example_parallelplot_1

Output

/usr/include/c++/12.2.1/bits/stl_vector.h:1123: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = double; _Alloc = std::allocator<double>; reference = double&; size_type = long unsigned int]: Assertion '__n < this->size()' failed.

Program received signal SIGABRT, Aborted.
0x00007ffff68a164c in ?? () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff68a164c in ?? () from /usr/lib/libc.so.6
#1  0x00007ffff6851938 in raise () from /usr/lib/libc.so.6
#2  0x00007ffff683b53d in abort () from /usr/lib/libc.so.6
#3  0x00007ffff6ad30a2 in std::__glibcxx_assert_fail (file=file@entry=0x5555556da118 "/usr/include/c++/12.2.1/bits/stl_vector.h", line=line@entry=1123, 
    function=function@entry=0x5555556daad0 "std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = double; _Alloc = std::allocator<double>; reference = double&; size_type = long unsigned int]", 
    condition=condition@entry=0x5555556da004 "__n < this->size()") at /usr/src/debug/gcc/gcc/libstdc++-v3/src/c++11/debug.cc:60
#4  0x00005555556b7006 in std::vector<double, std::allocator<double> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/12.2.1/bits/stl_vector.h:1121
#5  std::vector<double, std::allocator<double> >::operator[] (this=<optimized out>, __n=<optimized out>) at /usr/include/c++/12.2.1/bits/stl_vector.h:1121
#6  matplot::parallel_lines::data_string[abi:cxx11]() (this=0x5555557753a0) at /home/schueller/projects/matplotplusplus/source/matplot/axes_objects/parallel_lines.cpp:181
#7  0x000055555558dbbd in matplot::axes_type::run_plot_objects_command (this=0x55555576f6a0) at /home/schueller/projects/matplotplusplus/source/matplot/core/axes_type.cpp:947
#8  0x00005555555bc609 in matplot::figure_type::send_gnuplot_draw_commands (this=0x55555576f540) at /usr/include/c++/12.2.1/bits/shared_ptr_base.h:1665
#9  0x00005555555bcb55 in matplot::figure_type::draw (this=0x55555576f540) at /home/schueller/projects/matplotplusplus/source/matplot/core/figure_type.cpp:74
#10 matplot::figure_type::draw (this=0x55555576f540) at /home/schueller/projects/matplotplusplus/source/matplot/core/figure_type.cpp:43
#11 0x00005555555a7514 in matplot::axes_type::draw (this=0x55555576f6a0) at /home/schueller/projects/matplotplusplus/source/matplot/core/axes_type.cpp:42
#12 matplot::axes_silencer::~axes_silencer (this=0x7fffffffdc80, __in_chrg=<optimized out>) at /home/schueller/projects/matplotplusplus/source/matplot/core/axes_type.cpp:2341
#13 matplot::axes_silencer::~axes_silencer (this=0x7fffffffdc80, __in_chrg=<optimized out>) at /home/schueller/projects/matplotplusplus/source/matplot/core/axes_type.cpp:2338
#14 matplot::axes_type::parallelplot (this=0x55555576f6a0, X=std::vector of length 3, capacity 3 = {...}, line_spec=...) at /home/schueller/projects/matplotplusplus/source/matplot/core/axes_type.cpp:3250
#15 0x000055555557fb9b in matplot::parallelplot<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >>(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >) (x=std::vector of length 3, capacity 3 = {...}) at /usr/include/c++/12.2.1/bits/char_traits.h:395
#16 main () at /home/schueller/projects/matplotplusplus/examples/data_distribution/parallelplot/parallelplot_1.cpp:11

Platform

Environment Details:

Additional context first example I tried :)