Skip to content

Commit 4a41122

Browse files
Fix breakout (#53)
1 parent dd26f18 commit 4a41122

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎Apps/Breakout/main/Source/Breakout.cpp‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ static uint32_t getActionIconPadding(UiDensity uiDensity) {
167167
/* ── Event Callbacks (declared here so createWidgets can wire them up) ── */
168168

169169
static void onTick(lv_timer_t* timer);
170+
static void onGameAreaDeleted(lv_event_t* e);
170171
static void onPressed(lv_event_t* e);
171172
static void onClicked(lv_event_t* e);
172173
static void onKey(lv_event_t* e);
@@ -404,6 +405,7 @@ void breakoutCreateWidgets(lv_obj_t* parent, void* userData) {
404405
lv_obj_add_event_cb(ctx->gameArea, onClicked, LV_EVENT_SHORT_CLICKED, ctx);
405406
lv_obj_add_event_cb(ctx->gameArea, onKey, LV_EVENT_KEY, ctx);
406407
lv_obj_add_event_cb(ctx->gameArea, onReenterKeyMode, LV_EVENT_CLICKED, ctx);
408+
lv_obj_add_event_cb(ctx->gameArea, onGameAreaDeleted, LV_EVENT_DELETE, ctx);
407409

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

420-
void breakoutTeardown(Context* ctx) {
422+
// The window manager deletes the widgets when the app closes, and when another window covers it.
423+
// The game timer moves the widgets, so it must stop with them.
424+
static void onGameAreaDeleted(lv_event_t* e) {
425+
auto* ctx = static_cast<Context*>(lv_event_get_user_data(e));
421426
if (ctx->gameTimer) {
422427
lv_timer_delete(ctx->gameTimer);
423428
ctx->gameTimer = nullptr;
424429
}
425-
if (ctx->gameArea) {
426-
lv_group_t* group = lv_group_get_default();
427-
if (group) lv_group_set_editing(group, false);
428-
lv_group_remove_obj(ctx->gameArea);
429-
}
430+
lv_group_t* group = lv_group_get_default();
431+
if (group) lv_group_set_editing(group, false);
430432
ctx->gameArea = nullptr;
431433
ctx->paddle = nullptr;
432434
for (int i = 0; i < MAX_BRICKS; i++) ctx->bricks[i] = nullptr;
@@ -441,7 +443,9 @@ void breakoutTeardown(Context* ctx) {
441443
ctx->livesLabel = nullptr;
442444
ctx->messageLabel = nullptr;
443445
ctx->soundBtnIcon = nullptr;
446+
}
444447

448+
void breakoutTeardown(Context* ctx) {
445449
// Clean up sfx engine
446450
if (ctx->sfxEngine) {
447451
ctx->sfxEngine->stop();

‎Apps/Breakout/main/Source/Breakout.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,5 @@ struct Context {
131131
/** window_manager_create()'s WindowCreateWidgetsFn - @a userData is the Context* for this instance. */
132132
void breakoutCreateWidgets(lv_obj_t* parent, void* userData);
133133

134-
/** Releases resources acquired while the window was shown (sfx engine, LVGL group/timer). Call once the window is torn down. */
134+
/** Releases the sfx engine. Call once the window is torn down. */
135135
void breakoutTeardown(Context* ctx);

‎Apps/Breakout/manifest.properties‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ manifest.version=0.3
22
target.sdk=0.8.0-dev
33
target.platforms=esp32,esp32s3,esp32c6,esp32p4
44
id=tactility.breakout
5-
version.name=0.18.0
6-
version.code=18
5+
version.name=0.19.0
6+
version.code=19
77
name=Breakout
88
description=Classic brick-breaking arcade game
99
app.0.id=tactility.breakout

0 commit comments

Comments
 (0)