Made entity parser give more useful errors and fixed the errors that were while I was at it

This commit is contained in:
2016-01-27 15:12:34 +01:00
parent 6615fe9438
commit 181017313d
10 changed files with 86 additions and 73 deletions
+6 -34
View File
@@ -29,41 +29,9 @@ enum _LOG_LEVEL
extern _LOG_LEVEL LOG_LEVEL; extern _LOG_LEVEL LOG_LEVEL;
const static char* _LOG_LEVEL_PREFIX[] = extern const char* _LOG_LEVEL_PREFIX[];
{
"EE: ",
"",
"WW: ",
"DD: "
};
static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...) extern void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...);
{
if (logLevel > LOG_LEVEL) {
return;
}
char* message = nullptr;
va_list args;
va_start(args, format);
size_t size = vsnprintf(message, 0, format, args) + 1;
va_end(args);
va_start(args, format);
message = new char[size];
vsnprintf(message, size, format, args);
va_end(args);
if (logLevel == LOG_LEVEL_ERROR) {
std::cerr << file << ":" << line << " " << func << std::endl;
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
} else {
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
}
delete[] message;
}
#define LOG(logLevel, format, ...) \ #define LOG(logLevel, format, ...) \
_LOG(logLevel, __BASE_FILE__, __func__, __LINE__, format, ##__VA_ARGS__) _LOG(logLevel, __BASE_FILE__, __func__, __LINE__, format, ##__VA_ARGS__)
@@ -77,7 +45,11 @@ static void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsign
#define LOG_INFO(format, ...) \ #define LOG_INFO(format, ...) \
LOG(LOG_LEVEL_INFO, format, ##__VA_ARGS__) LOG(LOG_LEVEL_INFO, format, ##__VA_ARGS__)
#ifdef DEBUG
#define LOG_DEBUG(format, ...) \ #define LOG_DEBUG(format, ...) \
LOG(LOG_LEVEL_DEBUG, format, ##__VA_ARGS__) LOG(LOG_LEVEL_DEBUG, format, ##__VA_ARGS__)
#else
#define LOG_DEBUG(format, ...)
#endif
#endif // Logging_h__ #endif // Logging_h__
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Animation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Animation.xsd"> <Animation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Animation.xsd">
<Name></Name>
<Time>0</Time> <Time>0</Time>
<Speed>0</Speed> <Speed>0</Speed>
<Loop>true</Loop> <Loop>true</Loop>
+1 -12
View File
@@ -2,18 +2,7 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/> <xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:include schemaLocation="../Types/TeamEnum.xsd"/>
<xs:complexType name="TeamEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Spectator" type="xs:integer" fixed="1" minOccurs="0"/>
<xs:element name="Red" type="xs:integer" fixed="2" minOccurs="0"/>
<xs:element name="Blue" type="xs:integer" fixed="3" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="CapturePoint"> <xs:element name="CapturePoint">
<xs:annotation> <xs:annotation>
+1 -1
View File
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Listener xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Listener.xsd"/> <HealthHUD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="HealthHUD.xsd"/>
+1 -12
View File
@@ -2,18 +2,7 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types"> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/> <xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:include schemaLocation="../Types/TeamEnum.xsd"/>
<xs:complexType name="TeamEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Spectator" type="xs:integer" fixed="1" minOccurs="0"/>
<xs:element name="Red" type="xs:integer" fixed="2" minOccurs="0"/>
<xs:element name="Blue" type="xs:integer" fixed="3" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Team"> <xs:element name="Team">
<xs:annotation> <xs:annotation>
+2 -2
View File
@@ -47,7 +47,7 @@
<xs:element ref="Entity" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="Entity" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="EntityRef" minOccurs="0" maxOccurs="unbounded"> <xs:element name="EntityRef" minOccurs="0" maxOccurs="unbounded">
<xs:complexType> <xs:complexType>
<xs:attribute name="file" type="xs:string" minOccurs="0"/> <xs:attribute name="file" type="xs:string"/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:sequence> </xs:sequence>
@@ -55,7 +55,7 @@
</xs:element> </xs:element>
</xs:all> </xs:all>
<xs:attribute ref="xml:base"/> <xs:attribute ref="xml:base"/>
<xs:attribute name="name" type="xs:string" minOccurs="0" default=""/> <xs:attribute name="name" type="xs:string" default=""/>
</xs:complexType> </xs:complexType>
</xs:element> </xs:element>
</xs:schema> </xs:schema>
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:complexType name="TeamEnum" mixed="true">
<xs:complexContent>
<xs:extension base="t:enum">
<xs:choice>
<xs:element name="Spectator" type="t:int" fixed="1" minOccurs="0"/>
<xs:element name="Red" type="t:int" fixed="2" minOccurs="0"/>
<xs:element name="Blue" type="t:int" fixed="3" minOccurs="0"/>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
+20 -10
View File
@@ -20,7 +20,7 @@ void EntityFile::Parse(const EntityFileHandler* handler) const
{ {
using namespace xercesc; using namespace xercesc;
EntityFileSAXHandler saxHandler(handler, nullptr); EntityFileSAXHandler saxHandler(handler, m_SAX2XMLReader);
setReaderFeatures(m_SAX2XMLReader); setReaderFeatures(m_SAX2XMLReader);
m_SAX2XMLReader->setContentHandler(&saxHandler); m_SAX2XMLReader->setContentHandler(&saxHandler);
m_SAX2XMLReader->setErrorHandler(&saxHandler); m_SAX2XMLReader->setErrorHandler(&saxHandler);
@@ -37,6 +37,7 @@ void EntityFile::setReaderFeatures(xercesc::SAX2XMLReader* reader)
reader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); reader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
reader->setFeature(XMLUni::fgXercesSchema, true); reader->setFeature(XMLUni::fgXercesSchema, true);
reader->setFeature(XMLUni::fgXercesSchemaFullChecking, true); reader->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
reader->setFeature(XMLUni::fgXercesCalculateSrcOfs, true);
} }
std::size_t EntityFile::GetTypeStride(std::string typeName) std::size_t EntityFile::GetTypeStride(std::string typeName)
@@ -111,8 +112,9 @@ void EntityFile::WriteValueData(char* outData, const ComponentInfo::Field_t& fie
} catch (const boost::bad_lexical_cast&) { } } catch (const boost::bad_lexical_cast&) { }
} }
EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader) : m_Handler(handler) EntityFileSAXHandler::EntityFileSAXHandler(const EntityFileHandler* handler, xercesc::SAX2XMLReader* reader)
, m_Reader(reader) : m_Handler(handler)
, m_Reader(reader)
{ {
// 0 is imaginary base parent // 0 is imaginary base parent
m_EntityStack.push(0); m_EntityStack.push(0);
@@ -188,21 +190,29 @@ void EntityFileSAXHandler::characters(const XMLCh* const chars, const XMLSize_t
void EntityFileSAXHandler::fatalError(const xercesc::SAXParseException& e) void EntityFileSAXHandler::fatalError(const xercesc::SAXParseException& e)
{ {
XS::ToString s(e.getMessage()); std::string message = XS::ToString(e.getMessage());
LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); std::string systemId = XS::ToString(e.getSystemId());
//throw e; XMLFileLoc line = e.getLineNumber();
XMLFileLoc column = e.getColumnNumber();
LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tFatal Error: %s", systemId.c_str(), line, column, message.c_str());
} }
void EntityFileSAXHandler::error(const xercesc::SAXParseException& e) void EntityFileSAXHandler::error(const xercesc::SAXParseException& e)
{ {
XS::ToString s(e.getMessage()); std::string message = XS::ToString(e.getMessage());
LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); std::string systemId = XS::ToString(e.getSystemId());
XMLFileLoc line = e.getLineNumber();
XMLFileLoc column = e.getColumnNumber();
LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tError: %s", systemId.c_str(), line, column, message.c_str());
} }
void EntityFileSAXHandler::warning(const xercesc::SAXParseException& e) void EntityFileSAXHandler::warning(const xercesc::SAXParseException& e)
{ {
XS::ToString s(e.getMessage()); std::string message = XS::ToString(e.getMessage());
LOG_ERROR("SAXParseException: %s", ((std::string)s).c_str()); std::string systemId = XS::ToString(e.getSystemId());
XMLFileLoc line = e.getLineNumber();
XMLFileLoc column = e.getColumnNumber();
LOG_ERROR("SAXParseException\n\tLocation: %s:%i:%i\n\tWarning: %s", systemId.c_str(), line, column, message.c_str());
} }
void EntityFileSAXHandler::onStartEntity(const xercesc::Attributes& attrs) void EntityFileSAXHandler::onStartEntity(const xercesc::Attributes& attrs)
+37 -1
View File
@@ -4,4 +4,40 @@
_LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG; _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_DEBUG;
#else #else
_LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO; _LOG_LEVEL LOG_LEVEL = LOG_LEVEL_INFO;
#endif #endif
const char* _LOG_LEVEL_PREFIX[] =
{
"EE: ",
"",
"WW: ",
"DD: "
};
void _LOG(_LOG_LEVEL logLevel, const char* file, const char* func, unsigned int line, const char* format, ...)
{
if (logLevel > LOG_LEVEL) {
return;
}
char* message = nullptr;
va_list args;
va_start(args, format);
size_t size = vsnprintf(message, 0, format, args) + 1;
va_end(args);
va_start(args, format);
message = new char[size];
vsnprintf(message, size, format, args);
va_end(args);
if (logLevel == LOG_LEVEL_ERROR) {
std::cerr << file << ":" << line << " " << func << std::endl;
std::cerr << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
} else {
std::cout << _LOG_LEVEL_PREFIX[logLevel] << message << std::endl;
}
delete[] message;
}
-1
View File
@@ -34,7 +34,6 @@ void DrawBloomPass::InitializeShaderPrograms()
void DrawBloomPass::InitializeBuffers() void DrawBloomPass::InitializeBuffers()
{ {
printf("x:%f\ny:%f", m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height);
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT); GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewPortSize().Width, m_Renderer->GetViewPortSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0))); m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));