Skip to main content
Kunal Varshney
Visitor II
November 4, 2020
Solved

I want to add a box dynamically on a button click in the buttoncallbackhandler() function.

  • November 4, 2020
  • 1 reply
  • 912 views

So I tried creating a box in the buttoncallback function as follows :

touchgfx::Box * box_temp = new touchgfx::Box();

    box_temp->setPosition(170,180,500,220);

    box_temp->setColor(touchgfx::Color::getColorFrom24BitRGB(255,255,255));

    box_temp->setVisible(true);

    add(*box_temp);

    box_temp->invalidate();

but on pressing the button the app freezes.

When tried to debug on trying to allocate memory using new the control reaches on

hardfault_handler(){}

Any suggestions?

This topic has been closed for replies.
Best answer by Alexandre RENOUX

Hello,

TouchGFX is allocating statically memory so you should avoid trying to create widgets dynamically.

One solution would be to create your box already in the Designer and then make it appear only at the right moment using setVisible(true). This way you ensure that the memory is correctly allocated for your Box and as long as the Box is not visible TouchGFX does not care about it (so it does not render it).

When your question is answered, please close this topic by choosing Select as Best.

/Alexandre

1 reply

Alexandre RENOUX
Alexandre RENOUXBest answer
Visitor II
November 9, 2020

Hello,

TouchGFX is allocating statically memory so you should avoid trying to create widgets dynamically.

One solution would be to create your box already in the Designer and then make it appear only at the right moment using setVisible(true). This way you ensure that the memory is correctly allocated for your Box and as long as the Box is not visible TouchGFX does not care about it (so it does not render it).

When your question is answered, please close this topic by choosing Select as Best.

/Alexandre