Initialization problem

Hi everyone
I’m using a NXP LPC1768 with mbed Application Board
I’ve a problem initializing some classes.
I had my a classes game like this:

#ifndef Game_H_
#define Game_H_

#include "LCatch.h"
#include "Pong.h"

class Game{
    public:
        LCatch lcatch;
        Pong pong;
        Game(lcdPin lcdPin, Joystick joystick);
};      

inline Game::Game(lcdPin lcdPin, Joystick joystick) : lcatch(lcdPin, joystick), pong(lcdPin, joystick){}

#endif //Game_H_

And if I have only LCatch or Pong all work fine but when I’m initializing both all the application stuck in the initialization phase.

For reference this is lcdPin and Joystik:

struct Joystick {
    DigitalIn left;
    DigitalIn up;
    DigitalIn right;
    DigitalIn down;
    DigitalIn center;
};

struct lcdPin{
    PinName MOSI;
    PinName SCK;
    PinName RESET;
    PinName A0;
    PinName nCS;
};

Both Pong and LCatch constructor are something like:

Pong::Pong(lcdPin lcdPin, Joystick joystickPin) : 
    lcd(lcdPin.MOSI, lcdPin.SCK, lcdPin.RESET, lcdPin.A0, lcdPin.nCS),
    joystick(joystickPin){
}

Hmm, have you tried running your code in the debugger? Is your code available online somewhere so I can take a look?

Hello and thanks for your availability, the complete code with the problem is available in this branch of my project.
Doing some other tests I started to assume that the problem could be the excessive RAM usage of my project but I haven’t had the chance to make sure yet.

So that I could run your project in the debugger, I made a fork and converted it to build with Mbed CE using the guide. What I found is, you’re creating a very large (almost 4kB!) object, Interaction at the start of your main() function. The default main stack size is only 4096 bytes, so I believe that this object, plus everything else on the stack, was going over the limit and your stack was colliding with other variables in the application.

If I move interaction to be declared a few lines above (see my latest commit to the forked repo), everything works!

p.s. let me know if you want to try switching over to Mbed CE for your project, it can make debugging issues like this a bit easier if you know how to use a debugger, plus it natively supports VS Code intellisense!

Thank you so much for your help, now I’m going to switch to Mbed CE so maybe I’ll became able to fix problem like this more easily

Sweet!
Here’s the toolchain setup guide (you probably did some of this already when setting up GCC_ARM toolchain), the VS Code setup guide, and the LPC1768 device info page. Hopefully those should cover all the info you need!