Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Picosystem with MinSizeRel only #755

Closed
ali1234 opened this issue Feb 16, 2022 · 0 comments · Fixed by #756
Closed

Crash on Picosystem with MinSizeRel only #755

ali1234 opened this issue Feb 16, 2022 · 0 comments · Fixed by #756

Comments

@ali1234
Copy link
Contributor

ali1234 commented Feb 16, 2022

The following code crashes only on Picosystem and only when built with MinSizeRel:

#include "32blit.hpp"

class StageScores {
    public:
        StageScores();
    private:
        static bool scores_loaded;
};

StageScores::StageScores()  {
    if (!scores_loaded) {
        scores_loaded = true; // <- commenting this line prevents the crash
    }
}

bool StageScores::scores_loaded = false;

static StageScores *stage = nullptr;

void init() {
    blit::set_screen_mode(blit::ScreenMode::hires, blit::PixelFormat::RGB565);
    if(blit::buttons & blit::Button::A) {
        stage = new StageScores();
    }
}

void update(uint32_t /*time*/) {

}

void render(uint32_t  time) {
    blit::screen.pen = blit::Pen((time>>2) & 0xff, 20, 20);
    blit::screen.clear();
}

(edited to remove inline declarations and only instantiate the class if a button is pressed.)

To reproduce:

  1. Clone 32blit-boilerplate
  2. Replace game.cpp with the above code
  3. Build with: cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_TOOLCHAIN_FILE=../../32blit-sdk/pico.toolchain ..
  4. Flash to Picosystem

If the code is working, the screen should flash red. If the screen is blank then the code has crashed.

As the comment says, writing to the static inline bool seems to be the cause of the crash.

I can't reproduce this with the Picosystem SDK or with just the Pico SDK.

The only difference between MinSizeRel and Release is that MinSizeRel sets -Os and Release sets -O3.

Note that the problem class is only instantiated if you press a button, but the crash happens anyway. This makes me think it is something to do with the crt0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant