cancel
Showing results for 
Search instead for 
Did you mean: 

Program crashed when I declare a array of Custom Container and add it to scrollableContainer in a constructor.

Wrend.1
Senior

I want to display a list of Custom Container in a scrollableContainer .

So I write the code like blow.

//declare in public
std::vector <menuDisplayContent> menuDisplayContanier;
 
/*--------------------------------------------------------------------*/
//in constructor
menuDisplayContanier.resize(5);
 
for (int i = 0; i < menuDisplayContanier.size(); i++)
{
        menuDisplayContanier[i].setY( i * 170);
	scrollableContainer1.add(menuDisplayContanier[i]);
}

It worked in PC simulator.But crashed when enter this screen in real board.

Firstly,I doubt the leak of heap is the reason. So I expand the heap size from 0x2000 to 0xF000. It crashed again. The heap size like below.

//in   startup_stm32f429xx.s   file
 
Stack_Size		EQU     0x4000
 
                AREA    STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem       SPACE   Stack_Size
__initial_sp
 
 
; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>
 
Heap_Size      EQU     0xF000 // I change the heap size here.
 
                AREA    HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem        SPACE   Heap_Size
__heap_limit
 
                PRESERVE8
                THUMB

Now, I can not find the reason. Is there other reason lead to this phenomenon?

5 REPLIES 5
Alexandre RENOUX
Principal

Hello,

Have you tried having this piece of code in your setupScreen ?

If this does not fix your issue, please provide more info. In which constructor ?

/Alexandre

Have a functional Hard Fault Handler so you can catch failures there.

The constructors may be called before external memory and peripherals are functional.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I put this piece of code in a "menuDislpayScreenView::menuDislpayScreenView():" constructor.

All the code like below:

// in menuDislpayScreenView.hpp
class menuDislpayScreenView : public menuDislpayScreenViewBase
{
public:
    menuDislpayScreenView();
    virtual ~menuDislpayScreenView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
 
//....
	std::vector <menuDisplayContent> menuDisplayContanier;
protected:
}
 
// in menuDislpayScreenView.cpp
menuDislpayScreenView::menuDislpayScreenView()
{
	
	menuDisplayContanier.resize(6);
 
	for (int i = 0; i < menuDisplayContanier.size(); i++)
	{
		menuDisplayContanier[i].setY( i * 170);
		scrollableContainer1.add(menuDisplayContanier[i]);
	}
}
 
void menuDislpayScreenView::setupScreen()
{
    menuDislpayScreenViewBase::setupScreen();
 
	for (int i = 0; i < menuDisplayContanier.size(); i++)
	{
		menuDisplayContanier[i].initialize();
	}
}

It worked in PC simulator, but crashed in real board.

And the when I stop the crashed program. It like below.

0693W000004GvPQQA0.png

How can I find the cause of hard fault.

In keil ,I only find the hard fault like below.0693W000004GvPQQA0.png

Have you tried what I suggested ?

Also, could you try with a normal array instead of a vector ?

/Alexandre