This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 0bc9579ab094c26d0ce41915f7dd40187fb8ba3c
Author: Cedric BAIL <[email protected]>
AuthorDate: Thu Nov 12 22:34:09 2026 -0600
examples: C++ examples let go of their objects before EFL shuts down
popup_cxx_example kept the popup and a button in file-scope wrappers.
They were only cleared by the windows' delete callbacks, so when the
loop ended any other way (SIGTERM, last window hidden) both still held a
reference at static destruction, which runs after Eo has shut down: "Eo
ID ... is not a valid object", a CRI and a core dump.
The state now lives in a shared struct captured by the callbacks that
use it, so it is owned by the objects that need it. A connection frees
its closure when its emitter is invalidated (the windows' deletion
invalidates the popup and the buttons too), so the state goes with the
widgets, before EFL shuts down.
calendar_cxx_example_02 is the same: the application, with its window,
was a file-scope object whose destructor ran after Eo was gone. It is
now owned by the delete callback of its window: the connection frees its
closure when the window is invalidated, either because the user closed
it or because EFL is shutting down, and the application goes with it.
"Good bye!" is printed once, when that happens.
The same file-scope pattern in slider (window) and bg 02 (window) is
gone as well, and spinner's unused global window is dropped.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/examples/elementary/bg_cxx_example_02.cc | 6 +-
src/examples/elementary/calendar_cxx_example_02.cc | 14 ++-
src/examples/elementary/popup_cxx_example.cc | 128 +++++++++++----------
src/examples/elementary/slider_cxx_example.cc | 9 +-
src/examples/elementary/spinner_cxx_example.cc | 2 -
5 files changed, 86 insertions(+), 73 deletions(-)
diff --git a/src/examples/elementary/bg_cxx_example_02.cc b/src/examples/elementary/bg_cxx_example_02.cc
index 0ba00f552a..fd1258b726 100644
--- a/src/examples/elementary/bg_cxx_example_02.cc
+++ b/src/examples/elementary/bg_cxx_example_02.cc
@@ -29,17 +29,15 @@
using efl::eo::instantiate;
-static efl::ui::Win win;
-
EAPI_MAIN void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
{
Efl_Loop_Arguments *args = static_cast<Efl_Loop_Arguments *>(ev->info);
- win = efl::ui::Win(instantiate);
+ efl::ui::Win win(instantiate);
win.text_set("Bg Image");
win.autohide_set(true);
- win.delete_request_event_cb_add([](){ win = nullptr; efl_exit(0); });
+ win.delete_request_event_cb_add([](){ efl_exit(0); });
std::string path;
/* argv[0] is the program itself; the image, if any, is the next one. */
diff --git a/src/examples/elementary/calendar_cxx_example_02.cc b/src/examples/elementary/calendar_cxx_example_02.cc
index 0d48fe97cf..220747442f 100644
--- a/src/examples/elementary/calendar_cxx_example_02.cc
+++ b/src/examples/elementary/calendar_cxx_example_02.cc
@@ -16,6 +16,7 @@
#define EFL_CXXPERIMENTAL
#include <Efl_Ui.hh>
+#include <memory>
using namespace std::placeholders;
using efl::eo::add;
@@ -28,12 +29,16 @@ struct appData
std::cout << "Good bye!" << std::endl;
}
- void create() {
+ /* The window's delete callback holds the application, so it lives exactly
+ * as long as the window does: the connection frees its closure when the
+ * window is invalidated, whether the user closed it or EFL is shutting
+ * down, and that is always before EFL is gone. */
+ void create(std::shared_ptr<appData> self) {
std::cout << "Hello!" << std::endl;
add(m_win);
m_win.text_set("Calendar Layout Formatting Example");
- m_win.delete_request_event_cb_add([&](){ destroy(); });
+ m_win.delete_request_event_cb_add([self](){ self->destroy(); });
efl::ui::Calendar cal(add, m_win);
m_win.content_set(cal);
@@ -67,12 +72,11 @@ private:
efl::ui::Win m_win;
};
-static appData app;
-
static void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
- app.create();
+ auto app = std::make_shared<appData>();
+ app->create(app);
}
EFL_MAIN()
diff --git a/src/examples/elementary/popup_cxx_example.cc b/src/examples/elementary/popup_cxx_example.cc
index 73228079c4..ad4234fda6 100644
--- a/src/examples/elementary/popup_cxx_example.cc
+++ b/src/examples/elementary/popup_cxx_example.cc
@@ -20,14 +20,23 @@
#include <Evas.hh>
#include <Efl_Ui.hh>
#include <iostream>
+#include <memory>
using efl::eo::instantiate;
-static efl::ui::Popup g_popup(nullptr);
-static efl::ui::Button g_repeat_events_test_btn(nullptr);
+/* What the callbacks share. It lives in the callbacks, so it goes away when
+ * the objects that own them are deleted, which is before EFL shuts down: a
+ * file-scope wrapper would still hold its reference (and release it) after
+ * Eo is gone whenever the loop ends without a window being closed by the user. */
+struct State
+{
+ efl::ui::Popup popup{nullptr};
+ efl::ui::Button repeat_events_test_btn{nullptr};
+};
+typedef std::shared_ptr<State> State_Ptr;
static efl::ui::Popup
-create_popup(efl::ui::Win win)
+create_popup(efl::ui::Win win, State_Ptr st)
{
efl::ui::Popup popup(instantiate, win);
@@ -37,8 +46,8 @@ create_popup(efl::ui::Win win)
popup.size_set({160, 160});
- auto timeout_cb(std::bind([]() {
- g_popup = nullptr;
+ auto timeout_cb(std::bind([st]() {
+ st->popup = nullptr;
std::cout << "Popup times out and it is deleted" << std::endl;
}));
efl::eolian::event_add(efl::ui::Popup::timeout_event, popup, timeout_cb);
@@ -52,6 +61,8 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
+ State_Ptr st = std::make_shared<State>();
+
//Popup Window
efl::ui::Win win(instantiate);
@@ -69,10 +80,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
//Popup Window Delete callback
auto wfunc_win(func_win._get_wref());
- auto win_del_cb(std::bind([wfunc_win]() {
- g_popup = nullptr;
- g_repeat_events_test_btn = nullptr;
- ::efl_del(wfunc_win->_eo_ptr());
+ auto win_del_cb(std::bind([wfunc_win, st]() {
+ st->popup = nullptr;
+ st->repeat_events_test_btn = nullptr;
+ if (auto w = wfunc_win.lock())
+ ::efl_del(w->_eo_ptr());
std::cout << "Window is deleted" << std::endl;
}));
efl::eolian::event_add(win.delete_request_event, win, win_del_cb);
@@ -80,10 +92,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
//Popup Function Window Delete callback
auto wwin(win._get_wref());
- auto func_win_del_cb(std::bind([wwin]() {
- g_popup = nullptr;
- g_repeat_events_test_btn = nullptr;
- ::efl_del(wwin->_eo_ptr());
+ auto func_win_del_cb(std::bind([wwin, st]() {
+ st->popup = nullptr;
+ st->repeat_events_test_btn = nullptr;
+ if (auto w = wwin.lock())
+ ::efl_del(w->_eo_ptr());
std::cout << "Window is deleted" << std::endl;
}));
efl::eolian::event_add(func_win.delete_request_event, func_win, func_win_del_cb);
@@ -100,11 +113,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
std::cout << "Repeat Test Button is clicked" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, repeat_events_test_btn, repeat_events_test_cb);
- g_repeat_events_test_btn = repeat_events_test_btn;
+ st->repeat_events_test_btn = repeat_events_test_btn;
//Popup
- g_popup = create_popup(win);
+ st->popup = create_popup(win, st);
//Create Button
@@ -113,15 +126,15 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
create_btn.position_set({0, 0});
create_btn.size_set({150, 50});
- auto create_cb(std::bind([wwin]() {
- if (g_popup)
+ auto create_cb(std::bind([wwin, st]() {
+ if (st->popup)
std::cout << "Efl.Ui.Popup is already created" << std::endl;
else {
std::cout << "Efl.Ui.Popup is created" << std::endl;
auto lwin = wwin.lock();
if (lwin) {
auto win = lwin.get();
- g_popup = create_popup(win);
+ st->popup = create_popup(win, st);
}
}
}));
@@ -134,11 +147,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
delete_btn.position_set({150, 0});
delete_btn.size_set({150, 50});
- auto delete_cb(std::bind([wwin]() {
- if (g_popup) {
- auto wpopup(g_popup._get_wref());
- ::efl_del(wpopup->_eo_ptr());
- g_popup = nullptr;
+ auto delete_cb(std::bind([wwin, st]() {
+ if (st->popup) {
+ ::efl_del(st->popup._eo_ptr());
+ st->popup = nullptr;
}
else
std::cout << "Efl.Ui.Popup does not exist" << std::endl;
@@ -153,8 +165,8 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
repeat_events_btn.size_set({150, 50});
auto wrepeat_events_btn(repeat_events_btn._get_wref());
- auto repeat_events_cb(std::bind([wrepeat_events_btn]() {
- if (!g_popup) return;
+ auto repeat_events_cb(std::bind([wrepeat_events_btn, st]() {
+ if (!st->popup) return;
auto lrepeat_events_btn = wrepeat_events_btn.lock();
if (!lrepeat_events_btn) return;
@@ -162,12 +174,12 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
auto repeat_events_btn = lrepeat_events_btn.get();
if (!repeat_events_btn) return;
- if (efl::eo::downcast<efl::canvas::Object>(g_popup.part_get("backwall")).repeat_events_get()) {
- efl::eo::downcast<efl::canvas::Object>(g_popup.part_get("backwall")).repeat_events_set(false);
+ if (efl::eo::downcast<efl::canvas::Object>(st->popup.part_get("backwall")).repeat_events_get()) {
+ efl::eo::downcast<efl::canvas::Object>(st->popup.part_get("backwall")).repeat_events_set(false);
repeat_events_btn.text_set("Set Repeat Events");
}
else {
- efl::eo::downcast<efl::canvas::Object>(g_popup.part_get("backwall")).repeat_events_set(true);
+ efl::eo::downcast<efl::canvas::Object>(st->popup.part_get("backwall")).repeat_events_set(true);
repeat_events_btn.text_set("Unset Repeat Events");
}
}));
@@ -181,8 +193,8 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
dummy_btn.size_set({150, 50});
auto wdummy_btn(dummy_btn._get_wref());
- auto dummy_cb(std::bind([wdummy_btn]() {
- if (!g_popup) return;
+ auto dummy_cb(std::bind([wdummy_btn, st]() {
+ if (!st->popup) return;
auto ldummy_btn = wdummy_btn.lock();
if (!ldummy_btn) return;
@@ -190,12 +202,12 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
auto dummy_btn = ldummy_btn.get();
if (!dummy_btn) return;
- if (g_repeat_events_test_btn.visible_get()) {
- g_repeat_events_test_btn.visible_set(false);
+ if (st->repeat_events_test_btn.visible_get()) {
+ st->repeat_events_test_btn.visible_set(false);
dummy_btn.text_set("Show Dummy Button");
}
else {
- g_repeat_events_test_btn.visible_set(true);
+ st->repeat_events_test_btn.visible_set(true);
dummy_btn.text_set("Hide Dummy Button");
}
}));
@@ -209,10 +221,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
backwall_btn.size_set({150, 50});
auto wbackwall_btn(backwall_btn._get_wref());
- auto backwall_cb(std::bind([wbackwall_btn]() {
+ auto backwall_cb(std::bind([wbackwall_btn, st]() {
static bool backwall_visible = false;
- if (!g_popup) return;
+ if (!st->popup) return;
auto lbackwall_btn = wbackwall_btn.lock();
if (!lbackwall_btn) return;
@@ -222,11 +234,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
backwall_visible = !backwall_visible;
if (backwall_visible) {
- efl::eo::downcast<efl::File>(g_popup.part_get("backwall")).file_set("./sky_01.jpg");
+ efl::eo::downcast<efl::File>(st->popup.part_get("backwall")).file_set("./sky_01.jpg");
backwall_btn.text_set("Unset Backwall");
}
else {
- efl::eo::downcast<efl::File>(g_popup.part_get("backwall")).file_set(nullptr);
+ efl::eo::downcast<efl::File>(st->popup.part_get("backwall")).file_set(nullptr);
backwall_btn.text_set("Set Backwall");
}
}));
@@ -239,10 +251,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
timeout_btn.position_set({150, 100});
timeout_btn.size_set({150, 50});
- auto timeout_set_cb(std::bind([]() {
- if (!g_popup) return;
+ auto timeout_set_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.closing_timeout_set(3);
+ st->popup.closing_timeout_set(3);
std::cout << "Timeout is set to 3 seconds" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, timeout_btn, timeout_set_cb);
@@ -254,10 +266,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
center_btn.position_set({0, 150});
center_btn.size_set({150, 50});
- auto center_align_cb(std::bind([]() {
- if (!g_popup) return;
+ auto center_align_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.align_set(EFL_UI_POPUP_ALIGN_CENTER);
+ st->popup.align_set(EFL_UI_POPUP_ALIGN_CENTER);
std::cout << "Align Center" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, center_btn, center_align_cb);
@@ -269,10 +281,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
top_btn.position_set({150, 150});
top_btn.size_set({150, 50});
- auto top_align_cb(std::bind([]() {
- if (!g_popup) return;
+ auto top_align_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.align_set(EFL_UI_POPUP_ALIGN_TOP);
+ st->popup.align_set(EFL_UI_POPUP_ALIGN_TOP);
std::cout << "Align Top" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, top_btn, top_align_cb);
@@ -284,10 +296,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
left_btn.position_set({0, 200});
left_btn.size_set({150, 50});
- auto left_align_cb(std::bind([]() {
- if (!g_popup) return;
+ auto left_align_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.align_set(EFL_UI_POPUP_ALIGN_LEFT);
+ st->popup.align_set(EFL_UI_POPUP_ALIGN_LEFT);
std::cout << "Align Left" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, left_btn, left_align_cb);
@@ -299,10 +311,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
right_btn.position_set({150, 200});
right_btn.size_set({150, 50});
- auto right_align_cb(std::bind([]() {
- if (!g_popup) return;
+ auto right_align_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.align_set(EFL_UI_POPUP_ALIGN_RIGHT);
+ st->popup.align_set(EFL_UI_POPUP_ALIGN_RIGHT);
std::cout << "Align Right" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, right_btn, right_align_cb);
@@ -314,10 +326,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
bottom_btn.position_set({0, 250});
bottom_btn.size_set({150, 50});
- auto bottom_align_cb(std::bind([]() {
- if (!g_popup) return;
+ auto bottom_align_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.align_set(EFL_UI_POPUP_ALIGN_BOTTOM);
+ st->popup.align_set(EFL_UI_POPUP_ALIGN_BOTTOM);
std::cout << "Align Bottom" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, bottom_btn, bottom_align_cb);
@@ -329,10 +341,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
position_btn.position_set({150, 250});
position_btn.size_set({150, 50});
- auto position_set_cb(std::bind([]() {
- if (!g_popup) return;
+ auto position_set_cb(std::bind([st]() {
+ if (!st->popup) return;
- g_popup.position_set({0, 0});
+ st->popup.position_set({0, 0});
std::cout << "Position is set to (0, 0)" << std::endl;
}));
efl::eolian::event_add(efl::input::Clickable::clicked_event, position_btn, position_set_cb);
diff --git a/src/examples/elementary/slider_cxx_example.cc b/src/examples/elementary/slider_cxx_example.cc
index 2c906561b4..0c975c6537 100644
--- a/src/examples/elementary/slider_cxx_example.cc
+++ b/src/examples/elementary/slider_cxx_example.cc
@@ -24,16 +24,17 @@
using namespace std::placeholders;
using efl::eo::instantiate;
-static efl::ui::Win win;
-
static void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
- win = efl::ui::Win(instantiate);
+ efl::ui::Win win(instantiate);
win.text_set("Slider example");
- win.delete_request_event_cb_add([](){ win._delete(); });
+ auto wwin(win._get_wref());
+ win.delete_request_event_cb_add([wwin](){
+ if (auto w = wwin.lock()) ::efl_del(w->_eo_ptr());
+ });
efl::ui::Box bx(instantiate, win);
win.content_set(bx);
diff --git a/src/examples/elementary/spinner_cxx_example.cc b/src/examples/elementary/spinner_cxx_example.cc
index 2393b16773..35afadea34 100644
--- a/src/examples/elementary/spinner_cxx_example.cc
+++ b/src/examples/elementary/spinner_cxx_example.cc
@@ -25,8 +25,6 @@
using namespace std::placeholders;
using efl::eo::instantiate;
-static efl::ui::Win win;
-
static void
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.