Skip to content

Commit 4201cab

Browse files
committed
Use shared_ptr for the screen history list.
1 parent fec4c8c commit 4201cab

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

lib/3rd_party_adapters/LVGL/Screen.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <math.h>
33
#include <stack>
44

5-
static std::stack<IScreen *> screenHistory;
5+
static std::stack<std::shared_ptr<IScreen>> screenHistory;
66

77
static inline void IScreen_leave()
88
{
@@ -12,8 +12,6 @@ static inline void IScreen_leave()
1212
//clear the current screen of lvgl
1313
lv_obj_clean(lv_scr_act());
1414

15-
//free up the memory of current screen
16-
delete screenHistory.top();
1715
//remove current screen
1816
screenHistory.pop();
1917
//draw previous screen
@@ -257,7 +255,7 @@ void ScreenMenu::draw()
257255
lv_scr_load(screen);
258256

259257
/* add the screen to the screens history list */
260-
screenHistory.push(this);
258+
screenHistory.push(shared_from_this());
261259
}
262260

263261
/**
@@ -468,5 +466,5 @@ void ScreenValueModifier::draw()
468466
lv_scr_load(screen);
469467

470468
/* add the screen to the screens history list */
471-
screenHistory.push(this);
469+
screenHistory.push(shared_from_this());
472470
}

lib/3rd_party_adapters/LVGL/Screen.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66

77
#include <lvgl.h>
8+
#include <memory>
89
#include <user_interaction/MenuItem.hpp>
910

1011
/**
@@ -25,7 +26,7 @@ class IScreen
2526
* it receives a list of menu items for it's topology
2627
*
2728
*/
28-
class ScreenMenu final : public IScreen
29+
class ScreenMenu final : public IScreen, std::enable_shared_from_this<ScreenMenu>
2930
{
3031
public:
3132
ScreenMenu(MenuItemList itemList);
@@ -41,7 +42,7 @@ class ScreenMenu final : public IScreen
4142
* @brief Screen for value modification
4243
*
4344
*/
44-
class ScreenValueModifier final : public IScreen
45+
class ScreenValueModifier final : public IScreen, std::enable_shared_from_this<ScreenValueModifier>
4546
{
4647
public:
4748
ScreenValueModifier(const MenuItemValue *const menuItem);

0 commit comments

Comments
 (0)