diff --git a/src/SFML/Main/MainAndroid.cpp b/src/SFML/Main/MainAndroid.cpp index 7399db161..27d75d74b 100644 --- a/src/SFML/Main/MainAndroid.cpp +++ b/src/SFML/Main/MainAndroid.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -485,6 +486,9 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* savedState, size_ getScreenSizeInPixels(activity, &states->screenSize.x, &states->screenSize.y); + // Redirect error messages to logcat + sf::err().rdbuf(&states->logcat); + // Launch the main thread sf::Thread* thread = new sf::Thread(sf::priv::main, states); thread->launch(); diff --git a/src/SFML/System/Android/Activity.cpp b/src/SFML/System/Android/Activity.cpp index 28655a35c..b5ba35d27 100644 --- a/src/SFML/System/Android/Activity.cpp +++ b/src/SFML/System/Android/Activity.cpp @@ -28,6 +28,29 @@ // Headers //////////////////////////////////////////////////////////// #include +#include + +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_INFO, "sfml-error", __VA_ARGS__)) + +LogcatStream::LogcatStream() : +std::streambuf() +{ + // Nothing to do +} + +std::streambuf::int_type LogcatStream::overflow (std::streambuf::int_type c) +{ + if (c == "\n"[0]) + { + m_message.push_back(c); + LOGE(m_message.c_str()); + m_message.clear(); + } + + m_message.push_back(c); + + return traits_type::not_eof(c); +} namespace sf { diff --git a/src/SFML/System/Android/Activity.hpp b/src/SFML/System/Android/Activity.hpp index 572b1975a..bd6bbc9a7 100644 --- a/src/SFML/System/Android/Activity.hpp +++ b/src/SFML/System/Android/Activity.hpp @@ -36,7 +36,19 @@ #include #include #include +#include +#include +class SFML_SYSTEM_API LogcatStream : public std::streambuf +{ +public: + LogcatStream(); + + std::streambuf::int_type overflow (std::streambuf::int_type c); + +private: + std::string m_message; +}; namespace sf { @@ -76,6 +88,8 @@ struct ActivityStates bool fullscreen; bool updated; + + LogcatStream logcat; }; SFML_SYSTEM_API ActivityStates* getActivity(ActivityStates* initializedStates=NULL, bool reset=false); diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 080320a3b..728cb52f3 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -90,7 +90,7 @@ if(SFML_OS_WINDOWS) list(APPEND SYSTEM_EXT_LIBS winmm) endif() if(SFML_OS_ANDROID) - list(APPEND SYSTEM_EXT_LIBS android) + list(APPEND SYSTEM_EXT_LIBS android log) endif() # define the sfml-system target