[Android] Redirect error messages to logcat by default

This commit is contained in:
Jonathan De Wachter 2014-07-08 17:59:33 +02:00
parent dd6b54d0eb
commit f491e94297
4 changed files with 42 additions and 1 deletions

View File

@ -42,6 +42,7 @@
#include <SFML/System/Sleep.hpp>
#include <SFML/System/Thread.hpp>
#include <SFML/System/Lock.hpp>
#include <SFML/System/Err.hpp>
#include <android/window.h>
#include <android/native_activity.h>
@ -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();

View File

@ -28,6 +28,29 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Android/Activity.hpp>
#include <android/log.h>
#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
{

View File

@ -36,7 +36,19 @@
#include <EGL/egl.h>
#include <vector>
#include <map>
#include <string>
#include <fstream>
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);

View File

@ -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