From 1bd62b4d14e068f8345d828f83953d6580be3f1c Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Fri, 20 Jun 2014 19:40:17 +0200 Subject: [PATCH] [Android] Fixed the app crashing on rotation Rotating the screen will restart the app with the new window/orientation. --- src/SFML/Main/MainAndroid.cpp | 5 ++++- src/SFML/System/Android/Activity.cpp | 4 ++-- src/SFML/System/Android/Activity.hpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index fd54e755..fdfbd826 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -200,6 +200,9 @@ static void onDestroy(ANativeActivity* activity) // Delete our allocated states delete states; + // Reset the activity pointer for all modules + sf::priv::getActivity(NULL, true); + // The application should now terminate } @@ -386,7 +389,7 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ states->terminated = false; // Share it across the SFML modules - sf::priv::getActivity(states); + sf::priv::getActivity(states, true); // These functions will update the activity states and therefore, will allow // SFML to be kept in the know diff --git a/src/SFML/System/Android/Activity.cpp b/src/SFML/System/Android/Activity.cpp index 11deab33..28655a35 100644 --- a/src/SFML/System/Android/Activity.cpp +++ b/src/SFML/System/Android/Activity.cpp @@ -33,11 +33,11 @@ namespace sf { namespace priv { -ActivityStates* getActivity(ActivityStates* initializedStates) +ActivityStates* getActivity(ActivityStates* initializedStates, bool reset) { static ActivityStates* states = NULL; - if (!states) + if (!states || reset) states = initializedStates; return states; diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index ab1ac3d3..e5c96786 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -74,7 +74,7 @@ struct ActivityStates bool updated; }; -SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=NULL); +SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=NULL, bool reset=false); } // namespace priv } // namespace sf