cancel
Showing results for 
Search instead for 
Did you mean: 

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

Kunal Varshney
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Alexandre RENOUX
Principal

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

View solution in original post

1 REPLY 1
Alexandre RENOUX
Principal

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