Skip to content

Commit 67f0349

Browse files
authored
Fix a crash during app shutdown (#13)
* Disconnect Ecore_Wl2_Display instead of destroy * This patch fixes the crash when the app is terminated Signed-off-by: Boram Bae <[email protected]> * Correct the order of resource release. * Use shared_ptr instead uniq_ptr for TizenNativeWindow and TizenNativeEGLWindow * Specify the order of resource release in the destructor Signed-off-by: Boram Bae <[email protected]>
1 parent 9e2c846 commit 67f0349

File tree

6 files changed

+31
-25
lines changed

6 files changed

+31
-25
lines changed

shell/platform/tizen/tizen_embedder_engine.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ static double GetDeviceDpi() {
3535
TizenEmbedderEngine::TizenEmbedderEngine(
3636
const FlutterWindowProperties& window_properties)
3737
: device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) {
38-
tizen_native_window = std::make_unique<TizenNativeWindow>(
38+
tizen_native_window = std::make_shared<TizenNativeWindow>(
3939
window_properties.x, window_properties.y, window_properties.width,
4040
window_properties.height);
41-
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window.get());
41+
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window);
4242

4343
// Run flutter task on Tizen main loop.
4444
// Tizen engine has four threads (GPU thread, UI thread, IO thread, platform
@@ -59,7 +59,11 @@ TizenEmbedderEngine::TizenEmbedderEngine(
5959
tizen_vsync_waiter_ = std::make_unique<TizenVsyncWaiter>();
6060
}
6161

62-
TizenEmbedderEngine::~TizenEmbedderEngine() { LoggerD("Destroy"); }
62+
TizenEmbedderEngine::~TizenEmbedderEngine() {
63+
LoggerD("Destroy");
64+
tizen_surface = nullptr;
65+
tizen_native_window = nullptr;
66+
}
6367

6468
// Attempts to load AOT data from the given path, which must be absolute and
6569
// non-empty. Logs and returns nullptr on failure.

shell/platform/tizen/tizen_embedder_engine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class TizenEmbedderEngine {
9595

9696
// The interface between the Flutter rasterizer and the platform.
9797
std::unique_ptr<TizenSurface> tizen_surface;
98-
std::unique_ptr<TizenNativeWindow> tizen_native_window;
98+
std::shared_ptr<TizenNativeWindow> tizen_native_window;
9999

100100
// The system channels for communicating between Flutter and the platform.
101101
std::unique_ptr<KeyEventChannel> key_event_channel;

shell/platform/tizen/tizen_native_window.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TizenWl2Display {
2424

2525
~TizenWl2Display() {
2626
if (wl2_display_) {
27-
ecore_wl2_display_destroy(wl2_display_);
27+
ecore_wl2_display_disconnect(wl2_display_);
2828
wl2_display_ = nullptr;
2929
}
3030
ecore_wl2_shutdown();
@@ -93,11 +93,12 @@ TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,
9393
"1");
9494
ecore_wl2_window_show(wl2_window_);
9595

96-
tizen_native_egl_window_ = std::make_unique<TizenNativeEGLWindow>(this, w, h);
96+
tizen_native_egl_window_ = std::make_shared<TizenNativeEGLWindow>(this, w, h);
9797
is_valid_ = true;
9898
}
9999

100100
TizenNativeWindow::~TizenNativeWindow() {
101+
tizen_native_egl_window_ = nullptr;
101102
if (wl2_window_) {
102103
ecore_wl2_window_free(wl2_window_);
103104
wl2_window_ = nullptr;

shell/platform/tizen/tizen_native_window.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ class TizenNativeWindow {
3939
~TizenNativeWindow();
4040
bool IsValid() { return is_valid_; }
4141
Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; }
42-
TizenNativeEGLWindow* GetTizenNativeEGLWindow() {
43-
return tizen_native_egl_window_.get();
42+
std::shared_ptr<TizenNativeEGLWindow> GetTizenNativeEGLWindow() {
43+
return tizen_native_egl_window_;
4444
};
4545
TizenNativeWindowGeometry GetGeometry();
4646

4747
private:
48-
std::unique_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
48+
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
4949
Ecore_Wl2_Window* wl2_window_{nullptr};
5050
bool is_valid_{false};
5151
};

shell/platform/tizen/tizen_surface_gl.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ static EGLResult<EGLConfig> ChooseEGLConfiguration(EGLDisplay display) {
5252
TizenEGLSurface::~TizenEGLSurface() {
5353
eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(),
5454
egl_surface_);
55+
tizen_native_egl_window_ = nullptr;
5556
}
5657

57-
TizenEGLContext::TizenEGLContext(TizenNativeEGLWindow* tizen_native_egl_window)
58+
TizenEGLContext::TizenEGLContext(
59+
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window)
5860
: tizen_native_egl_window_(tizen_native_egl_window) {
5961
EGLDisplay egl_display = tizen_native_egl_window_->GetEGLDisplayHandle();
6062
auto config = ChooseEGLConfiguration(egl_display);
@@ -100,6 +102,7 @@ TizenEGLContext::~TizenEGLContext() {
100102
egl_resource_context_) != EGL_TRUE) {
101103
LoggerE("Failed to destroy egl resource context");
102104
}
105+
tizen_native_egl_window_ = nullptr;
103106
}
104107

105108
std::unique_ptr<TizenEGLSurface>
@@ -117,7 +120,8 @@ bool TizenEGLContext::IsValid() {
117120
egl_resource_context_ != EGL_NO_CONTEXT;
118121
}
119122

120-
TizenSurfaceGL::TizenSurfaceGL(TizenNativeWindow* tizen_native_window)
123+
TizenSurfaceGL::TizenSurfaceGL(
124+
std::shared_ptr<TizenNativeWindow> tizen_native_window)
121125
: tizen_native_window_(tizen_native_window) {
122126
if (!tizen_native_window_->IsValid()) {
123127
LoggerE("Invalid native window");
@@ -344,14 +348,12 @@ void* TizenSurfaceGL::OnProcResolver(const char* name) {
344348
#undef GL_FUNC
345349

346350
TizenSurfaceGL::~TizenSurfaceGL() {
347-
if (IsValid()) {
348-
is_valid_ = false;
349-
Destroy();
350-
}
351+
tizen_egl_window_surface_ = nullptr;
352+
tizen_egl_pbuffer_surface_ = nullptr;
353+
tizen_context_gl_ = nullptr;
354+
tizen_native_window_ = nullptr;
351355
}
352356

353-
void TizenSurfaceGL::Destroy() { LoggerD("Destroy"); }
354-
355357
void TizenSurfaceGL::SetSize(int32_t width, int32_t height) {
356358
// FIXME : I think we have to find another way.
357359
LoggerD("Resize egl window %d %d", width, height);

shell/platform/tizen/tizen_surface_gl.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class TizenEGLSurface {
2525
public:
26-
TizenEGLSurface(TizenNativeEGLWindow* tizen_native_egl_window,
26+
TizenEGLSurface(std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window,
2727
EGLSurface egl_surface)
2828
: tizen_native_egl_window_(tizen_native_egl_window),
2929
egl_surface_(egl_surface){};
@@ -32,13 +32,14 @@ class TizenEGLSurface {
3232
EGLSurface GetEGLSurfaceHandle() { return egl_surface_; };
3333

3434
private:
35-
TizenNativeEGLWindow* tizen_native_egl_window_;
35+
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
3636
EGLSurface egl_surface_{EGL_NO_SURFACE};
3737
};
3838

3939
class TizenEGLContext {
4040
public:
41-
TizenEGLContext(TizenNativeEGLWindow* tizen_native_egl_window);
41+
TizenEGLContext(
42+
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window);
4243
~TizenEGLContext();
4344
bool IsValid();
4445
std::unique_ptr<TizenEGLSurface> CreateTizenEGLWindowSurface();
@@ -47,15 +48,15 @@ class TizenEGLContext {
4748
EGLContext GetEGLResourceContextHandle() { return egl_resource_context_; }
4849

4950
public:
50-
TizenNativeEGLWindow* tizen_native_egl_window_;
51+
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
5152
EGLConfig egl_config_{nullptr};
5253
EGLContext egl_context_{EGL_NO_CONTEXT};
5354
EGLContext egl_resource_context_{EGL_NO_CONTEXT};
5455
};
5556

5657
class TizenSurfaceGL : public TizenSurface {
5758
public:
58-
TizenSurfaceGL(TizenNativeWindow* tizen_native_window);
59+
TizenSurfaceGL(std::shared_ptr<TizenNativeWindow> tizen_native_window);
5960
~TizenSurfaceGL();
6061
bool OnMakeCurrent() override;
6162
bool OnClearCurrent() override;
@@ -66,11 +67,9 @@ class TizenSurfaceGL : public TizenSurface {
6667
bool IsValid() override { return is_valid_; };
6768
void SetSize(int32_t width, int32_t height) override;
6869

69-
void Destroy();
70-
7170
private:
7271
bool is_valid_{false};
73-
TizenNativeWindow* tizen_native_window_;
72+
std::shared_ptr<TizenNativeWindow> tizen_native_window_;
7473
std::unique_ptr<TizenEGLContext> tizen_context_gl_;
7574
std::unique_ptr<TizenEGLSurface> tizen_egl_window_surface_;
7675
std::unique_ptr<TizenEGLSurface> tizen_egl_pbuffer_surface_;

0 commit comments

Comments
 (0)