Skip to content

Commit

Permalink
Fix a crash during app shutdown (#13)
Browse files Browse the repository at this point in the history
* Disconnect Ecore_Wl2_Display instead of destroy

* This patch fixes the crash when the app is terminated

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* 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 <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 authored Dec 21, 2020
1 parent 9e2c846 commit 67f0349
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
10 changes: 7 additions & 3 deletions shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TizenNativeWindow>(
tizen_native_window = std::make_shared<TizenNativeWindow>(
window_properties.x, window_properties.y, window_properties.width,
window_properties.height);
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window.get());
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window);

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

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.
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/tizen_embedder_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TizenEmbedderEngine {

// The interface between the Flutter rasterizer and the platform.
std::unique_ptr<TizenSurface> tizen_surface;
std::unique_ptr<TizenNativeWindow> tizen_native_window;
std::shared_ptr<TizenNativeWindow> tizen_native_window;

// The system channels for communicating between Flutter and the platform.
std::unique_ptr<KeyEventChannel> key_event_channel;
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/tizen/tizen_native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<TizenNativeEGLWindow>(this, w, h);
tizen_native_egl_window_ = std::make_shared<TizenNativeEGLWindow>(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;
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/tizen/tizen_native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<TizenNativeEGLWindow> GetTizenNativeEGLWindow() {
return tizen_native_egl_window_;
};
TizenNativeWindowGeometry GetGeometry();

private:
std::unique_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
Ecore_Wl2_Window* wl2_window_{nullptr};
bool is_valid_{false};
};
Expand Down
18 changes: 10 additions & 8 deletions shell/platform/tizen/tizen_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ static EGLResult<EGLConfig> 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<TizenNativeEGLWindow> 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);
Expand Down Expand Up @@ -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<TizenEGLSurface>
Expand All @@ -117,7 +120,8 @@ bool TizenEGLContext::IsValid() {
egl_resource_context_ != EGL_NO_CONTEXT;
}

TizenSurfaceGL::TizenSurfaceGL(TizenNativeWindow* tizen_native_window)
TizenSurfaceGL::TizenSurfaceGL(
std::shared_ptr<TizenNativeWindow> tizen_native_window)
: tizen_native_window_(tizen_native_window) {
if (!tizen_native_window_->IsValid()) {
LoggerE("Invalid native window");
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 7 additions & 8 deletions shell/platform/tizen/tizen_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class TizenEGLSurface {
public:
TizenEGLSurface(TizenNativeEGLWindow* tizen_native_egl_window,
TizenEGLSurface(std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window,
EGLSurface egl_surface)
: tizen_native_egl_window_(tizen_native_egl_window),
egl_surface_(egl_surface){};
Expand All @@ -32,13 +32,14 @@ class TizenEGLSurface {
EGLSurface GetEGLSurfaceHandle() { return egl_surface_; };

private:
TizenNativeEGLWindow* tizen_native_egl_window_;
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
EGLSurface egl_surface_{EGL_NO_SURFACE};
};

class TizenEGLContext {
public:
TizenEGLContext(TizenNativeEGLWindow* tizen_native_egl_window);
TizenEGLContext(
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window);
~TizenEGLContext();
bool IsValid();
std::unique_ptr<TizenEGLSurface> CreateTizenEGLWindowSurface();
Expand All @@ -47,15 +48,15 @@ class TizenEGLContext {
EGLContext GetEGLResourceContextHandle() { return egl_resource_context_; }

public:
TizenNativeEGLWindow* tizen_native_egl_window_;
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
EGLConfig egl_config_{nullptr};
EGLContext egl_context_{EGL_NO_CONTEXT};
EGLContext egl_resource_context_{EGL_NO_CONTEXT};
};

class TizenSurfaceGL : public TizenSurface {
public:
TizenSurfaceGL(TizenNativeWindow* tizen_native_window);
TizenSurfaceGL(std::shared_ptr<TizenNativeWindow> tizen_native_window);
~TizenSurfaceGL();
bool OnMakeCurrent() override;
bool OnClearCurrent() override;
Expand All @@ -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<TizenNativeWindow> tizen_native_window_;
std::unique_ptr<TizenEGLContext> tizen_context_gl_;
std::unique_ptr<TizenEGLSurface> tizen_egl_window_surface_;
std::unique_ptr<TizenEGLSurface> tizen_egl_pbuffer_surface_;
Expand Down

0 comments on commit 67f0349

Please sign in to comment.