From 67f0349ccab7892df035fcc58556daebdfa65ad3 Mon Sep 17 00:00:00 2001 From: Boram Bae Date: Mon, 21 Dec 2020 10:43:11 +0900 Subject: [PATCH] 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 * 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 --- shell/platform/tizen/tizen_embedder_engine.cc | 10 +++++++--- shell/platform/tizen/tizen_embedder_engine.h | 2 +- shell/platform/tizen/tizen_native_window.cc | 5 +++-- shell/platform/tizen/tizen_native_window.h | 6 +++--- shell/platform/tizen/tizen_surface_gl.cc | 18 ++++++++++-------- shell/platform/tizen/tizen_surface_gl.h | 15 +++++++-------- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/shell/platform/tizen/tizen_embedder_engine.cc b/shell/platform/tizen/tizen_embedder_engine.cc index 6667a5ca0a426..62e26f34fda01 100644 --- a/shell/platform/tizen/tizen_embedder_engine.cc +++ b/shell/platform/tizen/tizen_embedder_engine.cc @@ -35,10 +35,10 @@ static double GetDeviceDpi() { TizenEmbedderEngine::TizenEmbedderEngine( const FlutterWindowProperties& window_properties) : device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) { - tizen_native_window = std::make_unique( + tizen_native_window = std::make_shared( window_properties.x, window_properties.y, window_properties.width, window_properties.height); - tizen_surface = std::make_unique(tizen_native_window.get()); + tizen_surface = std::make_unique(tizen_native_window); // Run flutter task on Tizen main loop. // Tizen engine has four threads (GPU thread, UI thread, IO thread, platform @@ -59,7 +59,11 @@ TizenEmbedderEngine::TizenEmbedderEngine( tizen_vsync_waiter_ = std::make_unique(); } -TizenEmbedderEngine::~TizenEmbedderEngine() { LoggerD("Destroy"); } +TizenEmbedderEngine::~TizenEmbedderEngine() { + LoggerD("Destroy"); + tizen_surface = nullptr; + tizen_native_window = nullptr; +} // Attempts to load AOT data from the given path, which must be absolute and // non-empty. Logs and returns nullptr on failure. diff --git a/shell/platform/tizen/tizen_embedder_engine.h b/shell/platform/tizen/tizen_embedder_engine.h index 47524db5cccca..f6c84373ede59 100644 --- a/shell/platform/tizen/tizen_embedder_engine.h +++ b/shell/platform/tizen/tizen_embedder_engine.h @@ -95,7 +95,7 @@ class TizenEmbedderEngine { // The interface between the Flutter rasterizer and the platform. std::unique_ptr tizen_surface; - std::unique_ptr tizen_native_window; + std::shared_ptr tizen_native_window; // The system channels for communicating between Flutter and the platform. std::unique_ptr key_event_channel; diff --git a/shell/platform/tizen/tizen_native_window.cc b/shell/platform/tizen/tizen_native_window.cc index 32c23370e597a..8e966aad8f793 100644 --- a/shell/platform/tizen/tizen_native_window.cc +++ b/shell/platform/tizen/tizen_native_window.cc @@ -24,7 +24,7 @@ class TizenWl2Display { ~TizenWl2Display() { if (wl2_display_) { - ecore_wl2_display_destroy(wl2_display_); + ecore_wl2_display_disconnect(wl2_display_); wl2_display_ = nullptr; } ecore_wl2_shutdown(); @@ -93,11 +93,12 @@ TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w, "1"); ecore_wl2_window_show(wl2_window_); - tizen_native_egl_window_ = std::make_unique(this, w, h); + tizen_native_egl_window_ = std::make_shared(this, w, h); is_valid_ = true; } TizenNativeWindow::~TizenNativeWindow() { + tizen_native_egl_window_ = nullptr; if (wl2_window_) { ecore_wl2_window_free(wl2_window_); wl2_window_ = nullptr; diff --git a/shell/platform/tizen/tizen_native_window.h b/shell/platform/tizen/tizen_native_window.h index 803fd863eb37e..8c8e7826609e7 100644 --- a/shell/platform/tizen/tizen_native_window.h +++ b/shell/platform/tizen/tizen_native_window.h @@ -39,13 +39,13 @@ class TizenNativeWindow { ~TizenNativeWindow(); bool IsValid() { return is_valid_; } Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; } - TizenNativeEGLWindow* GetTizenNativeEGLWindow() { - return tizen_native_egl_window_.get(); + std::shared_ptr GetTizenNativeEGLWindow() { + return tizen_native_egl_window_; }; TizenNativeWindowGeometry GetGeometry(); private: - std::unique_ptr tizen_native_egl_window_; + std::shared_ptr tizen_native_egl_window_; Ecore_Wl2_Window* wl2_window_{nullptr}; bool is_valid_{false}; }; diff --git a/shell/platform/tizen/tizen_surface_gl.cc b/shell/platform/tizen/tizen_surface_gl.cc index 70fc354be10e9..2a15af8f19002 100644 --- a/shell/platform/tizen/tizen_surface_gl.cc +++ b/shell/platform/tizen/tizen_surface_gl.cc @@ -52,9 +52,11 @@ static EGLResult ChooseEGLConfiguration(EGLDisplay display) { TizenEGLSurface::~TizenEGLSurface() { eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(), egl_surface_); + tizen_native_egl_window_ = nullptr; } -TizenEGLContext::TizenEGLContext(TizenNativeEGLWindow* tizen_native_egl_window) +TizenEGLContext::TizenEGLContext( + std::shared_ptr tizen_native_egl_window) : tizen_native_egl_window_(tizen_native_egl_window) { EGLDisplay egl_display = tizen_native_egl_window_->GetEGLDisplayHandle(); auto config = ChooseEGLConfiguration(egl_display); @@ -100,6 +102,7 @@ TizenEGLContext::~TizenEGLContext() { egl_resource_context_) != EGL_TRUE) { LoggerE("Failed to destroy egl resource context"); } + tizen_native_egl_window_ = nullptr; } std::unique_ptr @@ -117,7 +120,8 @@ bool TizenEGLContext::IsValid() { egl_resource_context_ != EGL_NO_CONTEXT; } -TizenSurfaceGL::TizenSurfaceGL(TizenNativeWindow* tizen_native_window) +TizenSurfaceGL::TizenSurfaceGL( + std::shared_ptr tizen_native_window) : tizen_native_window_(tizen_native_window) { if (!tizen_native_window_->IsValid()) { LoggerE("Invalid native window"); @@ -344,14 +348,12 @@ void* TizenSurfaceGL::OnProcResolver(const char* name) { #undef GL_FUNC TizenSurfaceGL::~TizenSurfaceGL() { - if (IsValid()) { - is_valid_ = false; - Destroy(); - } + tizen_egl_window_surface_ = nullptr; + tizen_egl_pbuffer_surface_ = nullptr; + tizen_context_gl_ = nullptr; + tizen_native_window_ = nullptr; } -void TizenSurfaceGL::Destroy() { LoggerD("Destroy"); } - void TizenSurfaceGL::SetSize(int32_t width, int32_t height) { // FIXME : I think we have to find another way. LoggerD("Resize egl window %d %d", width, height); diff --git a/shell/platform/tizen/tizen_surface_gl.h b/shell/platform/tizen/tizen_surface_gl.h index a8ce958d52818..5f0a56bf44edc 100644 --- a/shell/platform/tizen/tizen_surface_gl.h +++ b/shell/platform/tizen/tizen_surface_gl.h @@ -23,7 +23,7 @@ class TizenEGLSurface { public: - TizenEGLSurface(TizenNativeEGLWindow* tizen_native_egl_window, + TizenEGLSurface(std::shared_ptr tizen_native_egl_window, EGLSurface egl_surface) : tizen_native_egl_window_(tizen_native_egl_window), egl_surface_(egl_surface){}; @@ -32,13 +32,14 @@ class TizenEGLSurface { EGLSurface GetEGLSurfaceHandle() { return egl_surface_; }; private: - TizenNativeEGLWindow* tizen_native_egl_window_; + std::shared_ptr tizen_native_egl_window_; EGLSurface egl_surface_{EGL_NO_SURFACE}; }; class TizenEGLContext { public: - TizenEGLContext(TizenNativeEGLWindow* tizen_native_egl_window); + TizenEGLContext( + std::shared_ptr tizen_native_egl_window); ~TizenEGLContext(); bool IsValid(); std::unique_ptr CreateTizenEGLWindowSurface(); @@ -47,7 +48,7 @@ class TizenEGLContext { EGLContext GetEGLResourceContextHandle() { return egl_resource_context_; } public: - TizenNativeEGLWindow* tizen_native_egl_window_; + std::shared_ptr tizen_native_egl_window_; EGLConfig egl_config_{nullptr}; EGLContext egl_context_{EGL_NO_CONTEXT}; EGLContext egl_resource_context_{EGL_NO_CONTEXT}; @@ -55,7 +56,7 @@ class TizenEGLContext { class TizenSurfaceGL : public TizenSurface { public: - TizenSurfaceGL(TizenNativeWindow* tizen_native_window); + TizenSurfaceGL(std::shared_ptr tizen_native_window); ~TizenSurfaceGL(); bool OnMakeCurrent() override; bool OnClearCurrent() override; @@ -66,11 +67,9 @@ class TizenSurfaceGL : public TizenSurface { bool IsValid() override { return is_valid_; }; void SetSize(int32_t width, int32_t height) override; - void Destroy(); - private: bool is_valid_{false}; - TizenNativeWindow* tizen_native_window_; + std::shared_ptr tizen_native_window_; std::unique_ptr tizen_context_gl_; std::unique_ptr tizen_egl_window_surface_; std::unique_ptr tizen_egl_pbuffer_surface_;