Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions Apps/Breakout/main/Source/Breakout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ static uint32_t getActionIconPadding(UiDensity uiDensity) {
/* ── Event Callbacks (declared here so createWidgets can wire them up) ── */

static void onTick(lv_timer_t* timer);
static void onGameAreaDeleted(lv_event_t* e);
static void onPressed(lv_event_t* e);
static void onClicked(lv_event_t* e);
static void onKey(lv_event_t* e);
Expand Down Expand Up @@ -404,6 +405,7 @@ void breakoutCreateWidgets(lv_obj_t* parent, void* userData) {
lv_obj_add_event_cb(ctx->gameArea, onClicked, LV_EVENT_SHORT_CLICKED, ctx);
lv_obj_add_event_cb(ctx->gameArea, onKey, LV_EVENT_KEY, ctx);
lv_obj_add_event_cb(ctx->gameArea, onReenterKeyMode, LV_EVENT_CLICKED, ctx);
lv_obj_add_event_cb(ctx->gameArea, onGameAreaDeleted, LV_EVENT_DELETE, ctx);

// Keyboard focus - explicit enter/exit, no focus/defocus handlers
lv_group_t* group = lv_group_get_default();
Expand All @@ -417,16 +419,16 @@ void breakoutCreateWidgets(lv_obj_t* parent, void* userData) {
ctx->gameTimer = lv_timer_create(onTick, TICK_MS, ctx);
}

void breakoutTeardown(Context* ctx) {
// The window manager deletes the widgets when the app closes, and when another window covers it.
// The game timer moves the widgets, so it must stop with them.
static void onGameAreaDeleted(lv_event_t* e) {
auto* ctx = static_cast<Context*>(lv_event_get_user_data(e));
if (ctx->gameTimer) {
lv_timer_delete(ctx->gameTimer);
ctx->gameTimer = nullptr;
}
if (ctx->gameArea) {
lv_group_t* group = lv_group_get_default();
if (group) lv_group_set_editing(group, false);
lv_group_remove_obj(ctx->gameArea);
}
lv_group_t* group = lv_group_get_default();
if (group) lv_group_set_editing(group, false);
Comment thread
KenVanHoeylandt marked this conversation as resolved.
ctx->gameArea = nullptr;
ctx->paddle = nullptr;
for (int i = 0; i < MAX_BRICKS; i++) ctx->bricks[i] = nullptr;
Expand All @@ -441,7 +443,9 @@ void breakoutTeardown(Context* ctx) {
ctx->livesLabel = nullptr;
ctx->messageLabel = nullptr;
ctx->soundBtnIcon = nullptr;
}

void breakoutTeardown(Context* ctx) {
// Clean up sfx engine
if (ctx->sfxEngine) {
ctx->sfxEngine->stop();
Expand Down
2 changes: 1 addition & 1 deletion Apps/Breakout/main/Source/Breakout.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ struct Context {
/** window_manager_create()'s WindowCreateWidgetsFn - @a userData is the Context* for this instance. */
void breakoutCreateWidgets(lv_obj_t* parent, void* userData);

/** Releases resources acquired while the window was shown (sfx engine, LVGL group/timer). Call once the window is torn down. */
/** Releases the sfx engine. Call once the window is torn down. */
void breakoutTeardown(Context* ctx);
4 changes: 2 additions & 2 deletions Apps/Breakout/manifest.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ manifest.version=0.3
target.sdk=0.8.0-dev
target.platforms=esp32,esp32s3,esp32c6,esp32p4
id=tactility.breakout
version.name=0.18.0
version.code=18
version.name=0.19.0
version.code=19
name=Breakout
description=Classic brick-breaking arcade game
app.0.id=tactility.breakout
Expand Down
Loading