From f7561f5fa17ef538728e26c002c9f62c60f2dcb9 Mon Sep 17 00:00:00 2001 From: Jonathan De Wachter Date: Thu, 24 Jul 2014 10:03:11 +0200 Subject: [PATCH] Fixed EGL surface not recreated in the right thread --- src/SFML/Main/MainAndroid.cpp | 4 +-- src/SFML/Window/Android/WindowImplAndroid.cpp | 30 ++++++++++++++----- src/SFML/Window/Android/WindowImplAndroid.hpp | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 27d75d74..67d88db8 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -289,12 +289,12 @@ static void onNativeWindowCreated(ANativeActivity* activity, ANativeWindow* wind states->window = window; // Notify SFML mechanism - states->updated = false; sf::Event event; event.type = sf::Event::GainedFocus; states->forwardEvent(event); // Wait for the event to be taken into account by SFML + states->updated = false; while(!states->updated) { states->mutex.unlock(); @@ -314,12 +314,12 @@ static void onNativeWindowDestroyed(ANativeActivity* activity, ANativeWindow* wi states->window = NULL; // Notify SFML mechanism - states->updated = false; sf::Event event; event.type = sf::Event::LostFocus; states->forwardEvent(event); // Wait for the event to be taken into account by SFML + states->updated = false; while(!states->updated) { states->mutex.unlock(); diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index ad5d8714..7a7a60b0 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -49,6 +49,8 @@ WindowImplAndroid* WindowImplAndroid::singleInstance = NULL; //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(WindowHandle handle) : m_size(0, 0) +, m_windowBeingCreated(false) +, m_windowBeingDestroyed(false) { } @@ -56,6 +58,8 @@ WindowImplAndroid::WindowImplAndroid(WindowHandle handle) //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& title, unsigned long style, const ContextSettings& settings) : m_size(mode.width, mode.height) +, m_windowBeingCreated(false) +, m_windowBeingDestroyed(false) { ActivityStates* states = getActivity(NULL); Lock lock(states->mutex); @@ -94,6 +98,23 @@ void WindowImplAndroid::processEvents() { // Process incoming OS events ALooper_pollAll(0, NULL, NULL, NULL); + + ActivityStates* states = getActivity(NULL); + sf::Lock lock(states->mutex); + + if (m_windowBeingCreated) + { + states->context->createSurface(states->window); + m_windowBeingCreated = false; + } + + if (m_windowBeingDestroyed) + { + states->context->destroySurface(); + m_windowBeingDestroyed = false; + } + + states->updated = true; } @@ -164,21 +185,16 @@ void WindowImplAndroid::setKeyRepeatEnabled(bool enabled) void WindowImplAndroid::forwardEvent(const Event& event) { ActivityStates* states = getActivity(NULL); - Lock lock(states->mutex); if (event.type == Event::GainedFocus) { - states->context->createSurface(states->window); - WindowImplAndroid::singleInstance->m_size.x = ANativeWindow_getWidth(states->window); WindowImplAndroid::singleInstance->m_size.y = ANativeWindow_getHeight(states->window); - - states->updated = true; + WindowImplAndroid::singleInstance->m_windowBeingCreated = true; } else if (event.type == Event::LostFocus) { - states->context->destroySurface(); - states->updated = true; + WindowImplAndroid::singleInstance->m_windowBeingDestroyed = true; } WindowImplAndroid::singleInstance->pushEvent(event); diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index 5c8062e5..1d381aec 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -205,6 +205,8 @@ private: static int getUnicode(AInputEvent* event); Vector2u m_size; + bool m_windowBeingCreated; + bool m_windowBeingDestroyed; }; } // namespace priv