https://github.com/libsdl-org/Maelstrom/commit/c326556597bb58668e04dbbc8866f5b08046d340
From c326556597bb58668e04dbbc8866f5b08046d340 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 31 Oct 2012 21:41:25 -0700
Subject: [PATCH] Fixed build on Android
---
screenlib/UIElementThumbstick.cpp | 4 ++--
screenlib/UITemplates.cpp | 12 +++++++++++-
utils/loadxml.cpp | 24 ++++++++++++++++++++++++
utils/loadxml.h | 4 ++++
utils/rapidxml.h | 2 ++
5 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/screenlib/UIElementThumbstick.cpp b/screenlib/UIElementThumbstick.cpp
index d0e677d4..7925ef43 100644
--- a/screenlib/UIElementThumbstick.cpp
+++ b/screenlib/UIElementThumbstick.cpp
@@ -182,8 +182,8 @@ UIElementThumbstick::GetTouchPosition(const SDL_Event &event, int &x, int &y)
bool
UIElementThumbstick::GetTouchAngleAndDistance(int x, int y, float &angle, float &distance)
{
- int a = (x - m_startX);
- int b = (y - m_startY);
+ float a = (float)(x - m_startX);
+ float b = (float)(y - m_startY);
// The angle is in the 0 - 2PI range with 0 being the +Y axis
angle = M_PI - SDL_atan2(a, b);
diff --git a/screenlib/UITemplates.cpp b/screenlib/UITemplates.cpp
index 2708fbde..ed6cfd2d 100644
--- a/screenlib/UITemplates.cpp
+++ b/screenlib/UITemplates.cpp
@@ -22,6 +22,7 @@
#include <stdio.h>
#include "SDL.h"
#include "../physfs/physfs.h"
+#include "../utils/loadxml.h"
#include "UITemplates.h"
@@ -66,6 +67,15 @@ UITemplates::Load(const char *file)
m_data[size] = '\0';
PHYSFS_close(fp);
+#ifdef RAPIDXML_NO_EXCEPTIONS
+ gLoadXMLError = NULL;
+ m_doc.parse<0>(m_data);
+ if (gLoadXMLError) {
+ delete[] m_data;
+ m_data = NULL;
+ return false;
+ }
+#else
try {
m_doc.parse<0>(m_data);
} catch (rapidxml::parse_error e) {
@@ -73,7 +83,7 @@ UITemplates::Load(const char *file)
m_data = NULL;
return false;
}
-
+#endif // RAPIDXML_NO_EXCEPTIONS
m_hashTable = hash_create(NULL, HashTable_Hash,
HashTable_KeyMatch,
diff --git a/utils/loadxml.cpp b/utils/loadxml.cpp
index 6bb2faf3..76f01d87 100644
--- a/utils/loadxml.cpp
+++ b/utils/loadxml.cpp
@@ -22,6 +22,10 @@
#include "../physfs/physfs.h"
#include "loadxml.h"
+#ifdef RAPIDXML_NO_EXCEPTIONS
+const char *gLoadXMLError = NULL;
+#endif
+
bool
LoadXML(const char *file, char *&buffer, rapidxml::xml_document<> &doc)
{
@@ -51,6 +55,18 @@ LoadXML(const char *file, char *&buffer, rapidxml::xml_document<> &doc)
buffer[size] = '\0';
PHYSFS_close(fp);
+#ifdef RAPIDXML_NO_EXCEPTIONS
+ gLoadXMLError = NULL;
+ doc.parse<0>(buffer);
+ if (gLoadXMLError) {
+ /*
+ fprintf(stderr, "Warning: Couldn't parse %s: error: %s\n",
+ file, gLoadXMLError);
+ */
+ delete[] buffer;
+ return false;
+ }
+#else
try {
doc.parse<0>(buffer);
} catch (rapidxml::parse_error e) {
@@ -61,6 +77,14 @@ LoadXML(const char *file, char *&buffer, rapidxml::xml_document<> &doc)
delete[] buffer;
return false;
}
+#endif // RAPIDXML_NO_EXCEPTIONS
return true;
}
+
+#ifdef RAPIDXML_NO_EXCEPTIONS
+void rapidxml::parse_error_handler(const char *what, void *where)
+{
+ gLoadXMLError = what;
+}
+#endif // RAPIDXML_NO_EXCEPTIONS
diff --git a/utils/loadxml.h b/utils/loadxml.h
index f459fdd9..699aa2c1 100644
--- a/utils/loadxml.h
+++ b/utils/loadxml.h
@@ -23,6 +23,10 @@
#include "rapidxml.h"
+#ifdef RAPIDXML_NO_EXCEPTIONS
+extern const char *gLoadXMLError;
+#endif
+
extern bool LoadXML(const char *file, char *&buffer, rapidxml::xml_document<> &doc);
#endif /* _loadxml_h */
diff --git a/utils/rapidxml.h b/utils/rapidxml.h
index 6255ebb0..85be44e5 100644
--- a/utils/rapidxml.h
+++ b/utils/rapidxml.h
@@ -38,6 +38,8 @@ extern inline void * operator new (size_t, void * p) throw() { return p ; }
#endif // !USE_STL
+#define RAPIDXML_NO_EXCEPTIONS
+
#include "rapidxml.hpp"
#endif // _rapidxml_h