ArthurSonzogni / FTXUI

:computer: C++ Functional Terminal User Interface. :heart:
MIT License
6.97k stars 420 forks source link

Segfault when rendering Gridboxes #259

Closed NikolaDucak closed 2 years ago

NikolaDucak commented 2 years ago

Hello! I was looking for a TUI library for my project and I've found FTXUI. I've tried it & I love it so far, great job! After trying to use a gridbox I've gotten a segfault. This code should reproduce it:

gridbox({
         {
             text("1"),
             text("2"),
             text("3"),
             text("4"),
         },
         {},
         {},

Upon minor inspection, the root of the issue is in the consturctor of Gridbox, mainly the filler() is not inserted to lines due to while loop checking for y_size instead of x_size. Since in code above x_size is 4 and y_size is 3 it's gonna miss some fillers & later segfault on gridbox.cpp:55 in ComputeRequirement().

I'd be very happy to submit a pull request (my very first open source PR) but if you prefer to do this minor thing yourself that is fine also!

ArthurSonzogni commented 2 years ago

Thanks!

gridbox is very new. You are probably one of the first trying it. Thanks for finding yourself the cause of the bug!

I would be very happy getting PR for this! Don't hesitate.

Along the way, would you mind adding your regression test case into: https://github.com/ArthurSonzogni/FTXUI/blob/master/src/ftxui/dom/gridbox_test.cpp

// Regression test for https://github.com/ArthurSonzogni/FTXUI/issues/259
TEST(GridboxTest, UnfilledRectangular) {
  auto root = gridbox({
      {text("1"), text("2"), text("3"), text("4")},
      {},
      {},
  });

  [...]
}

You can run them using:

cmake .. -DFTXUI_BUILD_TESTS=ON;
make -j tests;
./tests;