Question

I made an Animation.cpp for my LED cube containig a 2dimensional array of uint16_t for each frame and each layer. I initialize the array in the .cpp and also have a var containing the amount of frames. But when it's running, the array seems to only have random data (from the ram) and the int w/ amount of frames is 0.

link to cpp: http://hastebin.com/kunemopece.avrasm

link to header: http://hastebin.com/duvijipeya.vala

I'm pretty much a beginner in CPP/GCC, so, what did I do wrong?

Was it helpful?

Solution

In C++11, you may directly do that:

class Animation
{
public:
    std::uint16_t frames[8][4] = {
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF},
        {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}
    };
    std::uint8_t currentFrame = 0;
};

In C++03, you have to use the constructor:

class Animation
{
public:
    Animation() : currentFrame(0)
    {
        for (int i = 0; i != 8; ++i) {
            for (int j = 0; j != 4; ++j) {
                frames[i][j] = 0xFFFF;
            }
        }
    }

    uint16_t frames[8][4];
    uint8_t currentFrame;
};

OTHER TIPS

Definition of frames in your class is different set of frames that you define in cpp. Try initialising your frames in Animation class constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top