Skip to content

freeze when returning a component from a function #664

Closed Answered by ArthurSonzogni
uyha-kwz asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @uyha-kwz

Your lambda captures decrease and increase declared from the stack by reference. It is not valid using them after the end of the function.

Your binary suffers from undefined behavior / memory safety issues.

Capture the Component (std::shared_ptr) by value in the lambda. (Not recommanded)

template <typename T>
auto number(T &source) -> ftxui::Component {
  using namespace ftxui;

  auto decrease  = Button("-", [&] { --source; });
  auto increase  = Button("+", [&] { ++source; });
  auto container = Container::Horizontal({decrease, increase});
  return Renderer(container, [decrease, increase, &source] {
    return hbox({
        decrease->Render(),
        text(std::to_string(…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@uyha-kwz
Comment options

@ArthurSonzogni
Comment options

@uyha-kwz
Comment options

@ArthurSonzogni
Comment options

@uyha-kwz
Comment options

Answer selected by uyha-kwz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #663 on June 04, 2023 12:51.