From 6fff7f0cff8ec7fdef3662e4c2f9da2052b33cfb Mon Sep 17 00:00:00 2001 From: wangpeiqiang Date: Tue, 8 Sep 2020 22:12:22 +0800 Subject: [PATCH] window: solve crash problem. Set destroy window in single function, to make window destroyed in message cycle thread. --- src/anbox/platform/sdl/platform.cpp | 10 ++++++++-- src/anbox/platform/sdl/window.cpp | 9 +++++++-- src/anbox/platform/sdl/window.h | 1 + src/anbox/wm/window.h | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/anbox/platform/sdl/platform.cpp b/src/anbox/platform/sdl/platform.cpp index 78bf4b36..16267084 100644 --- a/src/anbox/platform/sdl/platform.cpp +++ b/src/anbox/platform/sdl/platform.cpp @@ -298,11 +298,17 @@ void Platform::user_event_function(const SDL_Event &event) { window_manager_->remove_task(param->taskId); } } else if (event_type == USER_DESTROY_WINDOW) { + { + auto w = window_manager_->find_window_for_task(param->taskId); + if (w) { + w->destroy_window(); + } + } window_manager_->erase_task(param->taskId); auto it = tasks_.find(param->taskId); if (it != tasks_.end()) { - windows_.erase(it->second); - tasks_.erase(it); + windows_.erase(it->second); + tasks_.erase(it); } } delete param; diff --git a/src/anbox/platform/sdl/window.cpp b/src/anbox/platform/sdl/window.cpp index e6e0400a..6cd21e0c 100755 --- a/src/anbox/platform/sdl/window.cpp +++ b/src/anbox/platform/sdl/window.cpp @@ -152,8 +152,13 @@ Window::Window(const std::shared_ptr &renderer, SDL_ShowWindow(window_); } -Window::~Window() { - if (window_) SDL_DestroyWindow(window_); +Window::~Window() {} + +void Window::destroy_window() { + if (window_) { + SDL_DestroyWindow(window_); + window_ = NULL; + } } bool Window::title_event_filter(int x, int y) { diff --git a/src/anbox/platform/sdl/window.h b/src/anbox/platform/sdl/window.h index 51e39858..a7cc14ae 100755 --- a/src/anbox/platform/sdl/window.h +++ b/src/anbox/platform/sdl/window.h @@ -90,6 +90,7 @@ class Window : public std::enable_shared_from_this, public wm::Window { inline std::uint32_t get_property() { return visible_property; } + void destroy_window() override; private: static SDL_HitTestResult on_window_hit(SDL_Window *window, const SDL_Point *pt, void *data); diff --git a/src/anbox/wm/window.h b/src/anbox/wm/window.h index 9a28ff60..7a164cfe 100644 --- a/src/anbox/wm/window.h +++ b/src/anbox/wm/window.h @@ -65,6 +65,7 @@ class Window { std::string title() const; virtual bool checkResizeable() { return resizing_; } virtual void setResizing(bool resizing) { resizing_ = resizing; } + virtual void destroy_window() {} protected: graphics::Rect last_frame_; bool resizing_{false}; -- GitLab