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

Fix exit for Flappy Bird #191

Merged
merged 1 commit into from
Aug 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions applications/flappy_bird/flappy_bird.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static void flappy_game_render_callback(Canvas* const canvas, void* ctx) {
for(int i = 0; i < FLAPPY_PILAR_MAX; i++) {
const PILAR* pilar = &game_state->pilars[i];
if(pilar != NULL && pilar->visible) {
canvas_draw_dot(canvas, pilar->point.x, pilar->point.y + 10);
// canvas_draw_dot(canvas, pilar->point.x, pilar->point.y + 10);
canvas_draw_frame(
canvas, pilar->point.x, pilar->point.y, FLAPPY_GAB_WIDTH, pilar->height);

Expand Down Expand Up @@ -181,6 +181,9 @@ static void flappy_game_update_timer_callback(FuriMessageQueue* event_queue) {
}

int32_t flappy_game_app(void* p) {
UNUSED(p);
int32_t return_code = 0;

FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(GameEvent));

GameState* game_state = malloc(sizeof(GameState));
Expand All @@ -189,8 +192,8 @@ int32_t flappy_game_app(void* p) {
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, game_state, sizeof(GameState))) {
FURI_LOG_E(TAG, "cannot create mutex\r\n");
free(game_state);
return 255;
return_code = 255;
goto free_and_exit;
}

// Set system callbacks
Expand Down Expand Up @@ -248,11 +251,16 @@ int32_t flappy_game_app(void* p) {
release_mutex(&state_mutex, game_state);
}

furi_timer_free(timer);
view_port_enabled_set(view_port, false);
gui_remove_view_port(gui, view_port);
furi_record_close("gui");
view_port_free(view_port);
delete_mutex(&state_mutex);

free_and_exit:
free(game_state);
furi_message_queue_free(event_queue);

return 0;
}
return return_code;
}