Merge pull request #188 from EdgeTX/fix-183
Unregister LUA widgets when the factory is destroyed
This commit is contained in:
@@ -196,6 +196,12 @@ void registerWidget(const WidgetFactory * factory)
|
|||||||
getRegisteredWidgets().push_back(factory);
|
getRegisteredWidgets().push_back(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void unregisterWidget(const WidgetFactory * factory)
|
||||||
|
{
|
||||||
|
TRACE("unregister widget %s", factory->getName());
|
||||||
|
getRegisteredWidgets().remove(factory);
|
||||||
|
}
|
||||||
|
|
||||||
const WidgetFactory * getWidgetFactory(const char * name)
|
const WidgetFactory * getWidgetFactory(const char * name)
|
||||||
{
|
{
|
||||||
auto it = getRegisteredWidgets().cbegin();
|
auto it = getRegisteredWidgets().cbegin();
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ class Widget : public Button
|
|||||||
};
|
};
|
||||||
|
|
||||||
void registerWidget(const WidgetFactory * factory);
|
void registerWidget(const WidgetFactory * factory);
|
||||||
|
void unregisterWidget(const WidgetFactory * factory);
|
||||||
|
|
||||||
class WidgetFactory
|
class WidgetFactory
|
||||||
{
|
{
|
||||||
@@ -125,6 +126,8 @@ class WidgetFactory
|
|||||||
registerWidget(this);
|
registerWidget(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~WidgetFactory() {}
|
||||||
|
|
||||||
inline const char * getName() const
|
inline const char * getName() const
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
|
|||||||
@@ -187,6 +187,9 @@ void registerBitmapClass(lua_State * L);
|
|||||||
void luaSetInstructionsLimit(lua_State* L, int count);
|
void luaSetInstructionsLimit(lua_State* L, int count);
|
||||||
int luaLoadScriptFileToState(lua_State * L, const char * filename, const char * mode);
|
int luaLoadScriptFileToState(lua_State * L, const char * filename, const char * mode);
|
||||||
|
|
||||||
|
// Unregister LUA widget factories
|
||||||
|
void luaUnregisterWidgets();
|
||||||
|
|
||||||
#if LCD_W > 350
|
#if LCD_W > 350
|
||||||
#define RADIO_TOOL_NAME_MAXLEN 40
|
#define RADIO_TOOL_NAME_MAXLEN 40
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -225,6 +225,11 @@ class LuaWidgetFactory: public WidgetFactory
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~LuaWidgetFactory()
|
||||||
|
{
|
||||||
|
unregisterWidget(this);
|
||||||
|
}
|
||||||
|
|
||||||
Widget * create(FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init=true) const override
|
Widget * create(FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData, bool init=true) const override
|
||||||
{
|
{
|
||||||
if (lsWidgets == 0) return 0;
|
if (lsWidgets == 0) return 0;
|
||||||
@@ -507,3 +512,13 @@ void luaInitThemesAndWidgets()
|
|||||||
luaDoGc(lsWidgets, true);
|
luaDoGc(lsWidgets, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void luaUnregisterWidgets()
|
||||||
|
{
|
||||||
|
std::list<const WidgetFactory *> regWidgets(getRegisteredWidgets());
|
||||||
|
for (auto w : regWidgets) {
|
||||||
|
if (dynamic_cast<const LuaWidgetFactory*>(w)) {
|
||||||
|
delete w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1518,7 +1518,10 @@ void opentxClose(uint8_t shutdown)
|
|||||||
|
|
||||||
//TODO: In fact we want only to empty the trash (private method)
|
//TODO: In fact we want only to empty the trash (private method)
|
||||||
MainWindow::instance()->run();
|
MainWindow::instance()->run();
|
||||||
|
|
||||||
|
luaUnregisterWidgets();
|
||||||
luaClose(&lsWidgets);
|
luaClose(&lsWidgets);
|
||||||
|
lsWidgets = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SDCARD)
|
#if defined(SDCARD)
|
||||||
@@ -1532,6 +1535,11 @@ void opentxResume()
|
|||||||
TRACE("opentxResume");
|
TRACE("opentxResume");
|
||||||
|
|
||||||
sdMount();
|
sdMount();
|
||||||
|
#if defined(COLORLCD)
|
||||||
|
// reload widgets
|
||||||
|
luaInitThemesAndWidgets();
|
||||||
|
#endif
|
||||||
|
|
||||||
storageReadAll();
|
storageReadAll();
|
||||||
|
|
||||||
#if defined(COLORLCD)
|
#if defined(COLORLCD)
|
||||||
|
|||||||
Reference in New Issue
Block a user