Browse Source

Removing exceptions

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
8246d7e22f

+ 10 - 11
include/anki/misc/Xml.h

@@ -46,6 +46,7 @@ public:
 	XmlElement& operator=(const XmlElement& b)
 	{
 		m_el = b.m_el;
+		m_alloc = b.m_alloc;
 		return *this;
 	}
 
@@ -74,19 +75,21 @@ public:
 	Vector<F64, StackAllocator<F64>> getFloats() const;
 
 	/// Return the text inside as a Mat4
-	Mat4 getMat4() const;
+	ANKI_USE_RESULT Error getMat4(Mat4& out) const;
 
 	/// Return the text inside as a Vec3
-	Vec3 getVec3() const;
+	ANKI_USE_RESULT Error getVec3(Vec3& out) const;
 
 	/// Return the text inside as a Vec4
-	Vec4 getVec4() const;
+	ANKI_USE_RESULT Error getVec4(Vec4& out) const;
 
 	/// Get a child element quietly
-	XmlElement getChildElementOptional(const CString& name) const;
+	ANKI_USE_RESULT Error getChildElementOptional(
+		const CString& name, XmlElement& out) const;
 
-	/// Get a child element and throw exception if not found
-	XmlElement getChildElement(const CString& name) const;
+	/// Get a child element and print error if not found
+	ANKI_USE_RESULT Error getChildElement(
+		const CString& name, XmlElement& out) const;
 
 	/// Get the next element with the same name. Returns empty XmlElement if
 	/// it reached the end of the list
@@ -105,11 +108,7 @@ class XmlDocument
 public:
 	void loadFile(const CString& filename, StackAllocator<U8>& alloc);
 
-	XmlElement getChildElement(const CString& name)
-	{
-		XmlElement el(m_doc.FirstChildElement(&name[0]), m_alloc);
-		return el;
-	}
+	ANKI_USE_RESULT Error getChildElement(const CString& name, XmlElement& out);
 
 private:
 	tinyxml2::XMLDocument m_doc;

+ 82 - 57
src/misc/Xml.cpp

@@ -104,14 +104,15 @@ Vector<F64, StackAllocator<F64>> XmlElement::getFloats() const
 }
 
 //==============================================================================
-Mat4 XmlElement::getMat4() const
+Error XmlElement::getMat4(Mat4& out) const
 {
 	check();
 
 	const char* txt = m_el->GetText();
 	if(txt == nullptr)
 	{
-		throw ANKI_EXCEPTION("Failed to return Mat4");
+		ANKI_LOGE("Failed to return Mat4");
+		return ErrorCode::USER_DATA;
 	}
 
 	StringListBase<StackAllocator<char>> list = 
@@ -120,35 +121,32 @@ Mat4 XmlElement::getMat4() const
 
 	if(list.size() != 16)
 	{
-		throw ANKI_EXCEPTION("Expecting 16 elements for Mat4");
+		ANKI_LOGE("Expecting 16 elements for Mat4");
+		return ErrorCode::USER_DATA;
 	}
 
-	Mat4 out;
-
-	try
+	for(U i = 0; i < 16; i++)
 	{
-		for(U i = 0; i < 16; i++)
-		{
-			out[i] = list[i].toF64();
-		}
-	}
-	catch(const std::exception& e)
-	{
-		throw ANKI_EXCEPTION("Found non-float element for Mat4");
+		out[i] = list[i].toF64();
 	}
 
-	return out;
+	return ErrorCode::NONE;
 }
 
 //==============================================================================
-Vec3 XmlElement::getVec3() const
+Error XmlElement::getVec3(Vec3& out) const
 {
-	check();
+	Error err = check();
+	if(err)
+	{
+		return err;
+	}
 
 	const char* txt = m_el->GetText();
 	if(txt == nullptr)
 	{
-		throw ANKI_EXCEPTION("Failed to return Vec3");
+		ANKI_LOGE("Failed to return Vec3");
+		return ErrorCode::USER_DATA;
 	}
 
 	StringListBase<StackAllocator<char>> list = 
@@ -157,34 +155,31 @@ Vec3 XmlElement::getVec3() const
 
 	if(list.size() != 3)
 	{
-		throw ANKI_EXCEPTION("Expecting 3 elements for Vec3");
+		ANKI_LOGE("Expecting 3 elements for Vec3");
+		return ErrorCode::USER_DATA;
 	}
 
-	Vec3 out;
-
-	try
+	for(U i = 0; i < 3; i++)
 	{
-		for(U i = 0; i < 3; i++)
-		{
-			out[i] = list[i].toF64();
-		}
+		out[i] = list[i].toF64();
 	}
-	catch(const std::exception& e)
-	{
-		throw ANKI_EXCEPTION("Found non-float element for Vec3");
-	}
-
-	return out;
+	
+	return ErrorCode::NONE;
 }
 //==============================================================================
-Vec4 XmlElement::getVec4() const
+Error XmlElement::getVec4(Vec4& out) const
 {
-	check();
+	Error err = check();
+	if(err)
+	{
+		return err;
+	}
 
 	const char* txt = m_el->GetText();
 	if(txt == nullptr)
 	{
-		throw ANKI_EXCEPTION("Failed to return Vec4");
+		ANKI_LOGE("Failed to return Vec4");
+		return ErrorCode::USER_DATA;
 	}
 
 	StringListBase<StackAllocator<char>> list = 
@@ -193,44 +188,58 @@ Vec4 XmlElement::getVec4() const
 
 	if(list.size() != 4)
 	{
-		throw ANKI_EXCEPTION("Expecting 3 elements for Vec4");
+		ANKI_LOGE("Expecting 3 elements for Vec4");
+		return ErrorCode::USER_DATA;
 	}
 
-	Vec4 out;
+	for(U i = 0; i < 4; i++)
+	{
+		out[i] = list[i].toF64();
+	}
 
-	try
+	return ErrorCode::NONE;
+}
+
+//==============================================================================
+Error XmlElement::getChildElementOptional(
+	const CString& name, XmlElement& out) const
+{	
+	Error err = check();
+	if(!err)
 	{
-		for(U i = 0; i < 4; i++)
-		{
-			out[i] = list[i].toF64();
-		}
+		out = XmlElement(m_el->FirstChildElement(&name[0]), m_alloc);
 	}
-	catch(const std::exception& e)
+	else
 	{
-		throw ANKI_EXCEPTION("Found non-float element for Vec4");
+		out = XmlElement();
 	}
 
-	return out;
+	return err;
 }
 
 //==============================================================================
-XmlElement XmlElement::getChildElementOptional(const CString& name) const
+Error XmlElement::getChildElement(const CString& name, XmlElement& out) const
 {
-	check();
-	XmlElement out(m_el->FirstChildElement(&name[0]), m_alloc);
-	return out;
-}
+	Error err = check();
+	if(err)
+	{
+		out = XmlElement();
+		return err;
+	}
+
+	err = getChildElementOptional(name, out);
+	if(err)
+	{
+		return err;
+	}
 
-//==============================================================================
-XmlElement XmlElement::getChildElement(const CString& name) const
-{
-	check();
-	const XmlElement out = getChildElementOptional(name);
 	if(!out)
 	{
-		throw ANKI_EXCEPTION("Cannot find tag %s", &name[0]);
+		ANKI_LOGE("Cannot find tag %s", &name[0]);
+		err = ErrorCode::USER_DATA;
 	}
-	return out;
+	
+	return err;
 }
 
 //==============================================================================
@@ -263,4 +272,20 @@ void XmlDocument::loadFile(const CString& filename, StackAllocator<U8>& alloc)
 	}
 }
 
+//==============================================================================
+ANKI_USE_RESULT Error XmlDocument::getChildElement(
+	const CString& name, XmlElement& out)
+{
+	Error err = ErrorCode::NONE;
+	out = XmlElement(m_doc.FirstChildElement(&name[0]), m_alloc);
+
+	if(!out)
+	{
+		ANKI_LOGE("Cannot find tag %s", &name[0]);
+		err = ErrorCode::USER_DATA;
+	}
+
+	return err;
+}
+
 } // end namespace anki

+ 34 - 18
src/resource/Animation.cpp

@@ -25,7 +25,9 @@ void Animation::load(const CString& filename, ResourceInitializer& init)
 	{
 		XmlDocument doc;
 		doc.loadFile(filename, init.m_tempAlloc);
-		loadInternal(doc.getChildElement("animation"), init);
+		XmlElement el;
+		doc.getChildElement("animation", el);
+		loadInternal(el, init);
 	}
 	catch(const std::exception& e)
 	{
@@ -35,8 +37,9 @@ void Animation::load(const CString& filename, ResourceInitializer& init)
 
 //==============================================================================
 void Animation::loadInternal(
-	const XmlElement& el, ResourceInitializer& init)
+	const XmlElement& rootel, ResourceInitializer& init)
 {
+	XmlElement el;
 	m_startTime = MAX_F32;
 	F32 maxTime = MIN_F32;
 	auto& alloc = init.m_alloc;
@@ -48,7 +51,8 @@ void Animation::loadInternal(
 	U identScaleCount = 0;
 
 	// <repeat>
-	XmlElement repel = el.getChildElementOptional("repeat");
+	XmlElement repel;
+	rootel.getChildElementOptional("repeat", repel);
 	if(repel)
 	{
 		I64 tmp;
@@ -61,8 +65,10 @@ void Animation::loadInternal(
 	}
 
 	// <channels>
-	XmlElement channelsEl = el.getChildElement("channels");
-	XmlElement chEl = channelsEl.getChildElement("channel");
+	XmlElement channelsEl;
+	rootel.getChildElement("channels", channelsEl);
+	XmlElement chEl;
+	channelsEl.getChildElement("channel", chEl);
 
 	// For all channels
 	do
@@ -71,28 +77,31 @@ void Animation::loadInternal(
 		AnimationChannel& ch = m_channels.back();
 
 		// <name>
-		ch.m_name = chEl.getChildElement("name").getText();
+		chEl.getChildElement("name", el);
+		ch.m_name = el.getText();
 
 		XmlElement keysEl, keyEl;
 
 		// <positionKeys>
-		keysEl = chEl.getChildElementOptional("positionKeys");
+		chEl.getChildElementOptional("positionKeys", keysEl);
 		if(keysEl)
 		{
-			keyEl = keysEl.getChildElement("key");
+			keysEl.getChildElement("key", keyEl);
 			do
 			{
 				Key<Vec3> key;
 
 				// <time>
 				F64 tmp;
-				keyEl.getChildElement("time").getF64(tmp);
+				keyEl.getChildElement("time", el);
+				el.getF64(tmp);
 				key.m_time = tmp;
 				m_startTime = std::min(m_startTime, key.m_time);
 				maxTime = std::max(maxTime, key.m_time);
 
 				// <value>
-				key.m_value = keyEl.getChildElement("value").getVec3();
+				keyEl.getChildElement("value", el);
+				el.getVec3(key.m_value);
 
 				// push_back
 				ch.m_positions.push_back(key);
@@ -109,23 +118,27 @@ void Animation::loadInternal(
 		}
 
 		// <rotationKeys>
-		keysEl = chEl.getChildElement("rotationKeys");
+		chEl.getChildElement("rotationKeys", keysEl);
 		if(keysEl)
 		{
-			keyEl = keysEl.getChildElement("key");
+			keysEl.getChildElement("key", keyEl);
 			do
 			{
 				Key<Quat> key;
 
 				// <time>
 				F64 tmp;
-				keyEl.getChildElement("time").getF64(tmp);
+				keyEl.getChildElement("time", el);
+				el.getF64(tmp);
 				key.m_time = tmp;
 				m_startTime = std::min(m_startTime, key.m_time);
 				maxTime = std::max(maxTime, key.m_time);
 
 				// <value>
-				key.m_value = Quat(keyEl.getChildElement("value").getVec4());
+				Vec4 tmp2;
+				keyEl.getChildElement("value", el);
+				el.getVec4(tmp2);
+				key.m_value = Quat(tmp);
 
 				// push_back
 				ch.m_rotations.push_back(key);
@@ -142,23 +155,26 @@ void Animation::loadInternal(
 		}
 
 		// <scalingKeys>
-		keysEl = chEl.getChildElementOptional("scalingKeys");
+		chEl.getChildElementOptional("scalingKeys", keysEl);
 		if(keysEl)
 		{
-			XmlElement keyEl = keysEl.getChildElement("key");
+			XmlElement keyEl;
+			keysEl.getChildElement("key", keyEl);
 			do
 			{
 				Key<F32> key;
 
 				// <time>
 				F64 tmp;
-				keyEl.getChildElement("time").getF64(tmp);
+				keyEl.getChildElement("time", el);
+				el.getF64(tmp);
 				key.m_time = tmp;
 				m_startTime = std::min(m_startTime, key.m_time);
 				maxTime = std::max(maxTime, key.m_time);
 
 				// <value>
-				keyEl.getChildElement("value").getF64(tmp);
+				keyEl.getChildElement("value", el);
+				el.getF64(tmp);
 				key.m_value = tmp;
 
 				// push_back

+ 20 - 15
src/resource/Material.cpp

@@ -324,7 +324,9 @@ void Material::load(const CString& filename, ResourceInitializer& init)
 
 		XmlDocument doc;
 		doc.loadFile(filename, init.m_tempAlloc);
-		parseMaterialTag(doc.getChildElement("material"), init);
+		XmlElement el;
+		doc.getChildElement("material", el);
+		parseMaterialTag(el , init);
 	}
 	catch(std::exception& e)
 	{
@@ -337,10 +339,12 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 	ResourceInitializer& rinit)
 {
 	Error err = ErrorCode::NONE;
+	XmlElement el;
 
 	// levelsOfDetail
 	//
-	XmlElement lodEl = materialEl.getChildElementOptional("levelsOfDetail");
+	XmlElement lodEl;
+	materialEl.getChildElementOptional("levelsOfDetail", lodEl);
 
 	if(lodEl)
 	{
@@ -356,7 +360,8 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 
 	// shadow
 	//
-	XmlElement shadowEl = materialEl.getChildElementOptional("shadow");
+	XmlElement shadowEl;
+	materialEl.getChildElementOptional("shadow", shadowEl);
 
 	if(shadowEl)
 	{
@@ -368,18 +373,18 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 
 	// blendFunctions
 	//
-	XmlElement blendFunctionsEl =
-		materialEl.getChildElementOptional("blendFunctions");
+	XmlElement blendFunctionsEl;
+	materialEl.getChildElementOptional("blendFunctions", blendFunctionsEl);
 
 	if(blendFunctionsEl)
 	{
 		// sFactor
-		m_blendingSfactor = blendToEnum(
-			blendFunctionsEl.getChildElement("sFactor").getText());
+		blendFunctionsEl.getChildElement("sFactor", el);
+		m_blendingSfactor = blendToEnum(el.getText());
 
 		// dFactor
-		m_blendingDfactor = blendToEnum(
-			blendFunctionsEl.getChildElement("dFactor").getText());
+		blendFunctionsEl.getChildElement("dFactor", el);
+		m_blendingDfactor = blendToEnum(el.getText());
 	}
 	else
 	{
@@ -388,8 +393,8 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 
 	// depthTesting
 	//
-	XmlElement depthTestingEl =
-		materialEl.getChildElementOptional("depthTesting");
+	XmlElement depthTestingEl;
+	materialEl.getChildElementOptional("depthTesting", depthTestingEl);
 
 	if(depthTestingEl)
 	{
@@ -401,7 +406,8 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 
 	// wireframe
 	//
-	XmlElement wireframeEl = materialEl.getChildElementOptional("wireframe");
+	XmlElement wireframeEl;
+	materialEl.getChildElementOptional("wireframe", wireframeEl);
 
 	if(wireframeEl)
 	{
@@ -413,9 +419,8 @@ void Material::parseMaterialTag(const XmlElement& materialEl,
 
 	// shaderProgram
 	//
-	MaterialProgramCreator loader(
-		materialEl.getChildElement("programs"),
-		rinit.m_tempAlloc);
+	materialEl.getChildElement("programs", el);
+	MaterialProgramCreator loader(el, rinit.m_tempAlloc);
 
 	m_tessellation = loader.hasTessellation();
 	U tessCount = m_tessellation ? 2 : 1;

+ 45 - 25
src/resource/MaterialProgramCreator.cpp

@@ -101,7 +101,8 @@ void MaterialProgramCreator::parseProgramsTag(const XmlElement& el)
 	//
 	// First gather all the inputs
 	//
-	XmlElement programEl = el.getChildElement("program");
+	XmlElement programEl;
+	el.getChildElement("program", programEl);
 	do
 	{
 		parseInputsTag(programEl);
@@ -115,7 +116,7 @@ void MaterialProgramCreator::parseProgramsTag(const XmlElement& el)
 	//
 	// Then parse the includes, operations and other parts of the program
 	//
-	programEl = el.getChildElement("program");
+	el.getChildElement("program", programEl);
 	do
 	{
 		parseProgramTag(programEl);
@@ -142,8 +143,11 @@ void MaterialProgramCreator::parseProgramsTag(const XmlElement& el)
 void MaterialProgramCreator::parseProgramTag(
 	const XmlElement& programEl)
 {
+	XmlElement el;
+
 	// <type>
-	CString type = programEl.getChildElement("type").getText();
+	programEl.getChildElement("type", el);
+	CString type = el.getText();
 	GLbitfield glshaderbit;
 	GLenum glshader;
 	U shaderidx;
@@ -160,8 +164,10 @@ void MaterialProgramCreator::parseProgramTag(
 	}
 
 	// <includes></includes>
-	XmlElement includesEl = programEl.getChildElement("includes");
-	XmlElement includeEl = includesEl.getChildElement("include");
+	XmlElement includesEl;
+	programEl.getChildElement("includes", includesEl);
+	XmlElement includeEl;
+	includesEl.getChildElement("include", includeEl);
 
 	do
 	{
@@ -200,8 +206,10 @@ void MaterialProgramCreator::parseProgramTag(
 	// <operations></operations>
 	lines.push_back(ANKI_STRL("\nvoid main()\n{"));
 
-	XmlElement opsEl = programEl.getChildElement("operations");
-	XmlElement opEl = opsEl.getChildElement("operation");
+	XmlElement opsEl;
+	programEl.getChildElement("operations", opsEl);
+	XmlElement opEl;
+	opsEl.getChildElement("operation", opEl);
 	do
 	{
 		MPString out(m_alloc);
@@ -218,7 +226,9 @@ void MaterialProgramCreator::parseProgramTag(
 //==============================================================================
 void MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 {
-	XmlElement inputsEl = programEl.getChildElementOptional("inputs");
+	XmlElement el;
+	XmlElement inputsEl;
+	programEl.getChildElementOptional("inputs", inputsEl);
 	if(!inputsEl)
 	{
 		return;
@@ -228,23 +238,26 @@ void MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 	GLbitfield glshaderbit;
 	GLenum glshader;
 	U shaderidx;
-	getShaderInfo(
-		programEl.getChildElement("type").getText(), 
-		glshader, glshaderbit, shaderidx);
+	programEl.getChildElement("type", el);
+	getShaderInfo(el.getText(), glshader, glshaderbit, shaderidx);
 
-	XmlElement inputEl = inputsEl.getChildElement("input");
+	XmlElement inputEl;
+	inputsEl.getChildElement("input", inputEl);
 	do
 	{
 		Input inpvar(m_alloc);
 
 		// <name>
-		inpvar.m_name = inputEl.getChildElement("name").getText();
+		inputEl.getChildElement("name", el);
+		inpvar.m_name = el.getText();
 
 		// <type>
-		inpvar.m_type = inputEl.getChildElement("type").getText();
+		inputEl.getChildElement("type", el);
+		inpvar.m_type = el.getText();
 
 		// <value>
-		XmlElement valueEl = inputEl.getChildElement("value");
+		XmlElement valueEl;
+		inputEl.getChildElement("value", valueEl);
 		if(valueEl.getText())
 		{
 			inpvar.m_value = MPStringList::splitString(
@@ -252,7 +265,8 @@ void MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		}
 
 		// <const>
-		XmlElement constEl = inputEl.getChildElementOptional("const");
+		XmlElement constEl;
+		inputEl.getChildElementOptional("const", constEl);
 		if(constEl)
 		{
 			I64 tmp;
@@ -265,7 +279,8 @@ void MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		}
 
 		// <arraySize>
-		XmlElement arrSizeEl = inputEl.getChildElementOptional("arraySize");
+		XmlElement arrSizeEl;
+		inputEl.getChildElementOptional("arraySize", arrSizeEl);
 		if(arrSizeEl)
 		{
 			I64 tmp;
@@ -280,8 +295,8 @@ void MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		// <instanced>
 		if(inpvar.m_arraySize == 0)
 		{
-			XmlElement instancedEl = 
-				inputEl.getChildElementOptional("instanced");
+			XmlElement instancedEl;
+			inputEl.getChildElementOptional("instanced", instancedEl);
 
 			if(instancedEl)
 			{
@@ -416,14 +431,17 @@ void MaterialProgramCreator::parseOperationTag(
 	MPString& out)
 {
 	static const char OUT[] = {"out"};
+	XmlElement el;
 
 	// <id></id>
 	I64 tmp;
-	operationTag.getChildElement("id").getI64(tmp);
+	operationTag.getChildElement("id", el);
+	el.getI64(tmp);
 	I id = tmp;
 	
 	// <returnType></returnType>
-	XmlElement retTypeEl = operationTag.getChildElement("returnType");
+	XmlElement retTypeEl;
+	operationTag.getChildElement("returnType", retTypeEl);
 	MPString retType(retTypeEl.getText(), m_alloc);
 	MPString operationOut(m_alloc);
 	if(retType != "void")
@@ -433,17 +451,19 @@ void MaterialProgramCreator::parseOperationTag(
 	}
 	
 	// <function>functionName</function>
-	MPString funcName(
-		operationTag.getChildElement("function").getText(), m_alloc);
+	operationTag.getChildElement("function", el);
+	MPString funcName(el.getText(), m_alloc);
 	
 	// <arguments></arguments>
-	XmlElement argsEl = operationTag.getChildElementOptional("arguments");
+	XmlElement argsEl;
+	operationTag.getChildElementOptional("arguments", argsEl);
 	MPStringList argsList(m_alloc);
 	
 	if(argsEl)
 	{
 		// Get all arguments
-		XmlElement argEl = argsEl.getChildElement("argument");
+		XmlElement argEl;
+		argsEl.getChildElement("argument", argEl);
 		do
 		{
 			MPString arg(argEl.getText(), m_alloc);

+ 6 - 3
src/resource/Mesh.cpp

@@ -250,9 +250,12 @@ void BucketMesh::load(const CString& filename, ResourceInitializer& init)
 		XmlDocument doc;
 		doc.loadFile(filename, init.m_tempAlloc);
 
-		XmlElement rootEl = doc.getChildElement("bucketMesh");
-		XmlElement meshesEl = rootEl.getChildElement("meshes");
-		XmlElement meshEl = meshesEl.getChildElement("mesh");
+		XmlElement rootEl;
+		doc.getChildElement("bucketMesh", rootEl);
+		XmlElement meshesEl;
+		rootEl.getChildElement("meshes", meshesEl);
+		XmlElement meshEl;
+		meshesEl.getChildElement("mesh", meshEl);
 
 		m_vertsCount = 0;
 		m_subMeshes.reserve(4);

+ 27 - 21
src/resource/Model.cpp

@@ -292,17 +292,22 @@ void Model::load(const CString& filename, ResourceInitializer& init)
 	{
 		// Load
 		//
+		XmlElement el;
 		XmlDocument doc;
 		doc.loadFile(filename, init.m_tempAlloc);
 
-		XmlElement rootEl = doc.getChildElement("model");
+		XmlElement rootEl;
+		doc.getChildElement("model", rootEl);
 
 		// <collisionShape>
-		XmlElement collEl = rootEl.getChildElementOptional("collisionShape");
+		XmlElement collEl;
+		rootEl.getChildElementOptional("collisionShape", collEl);
 		if(collEl)
 		{
-			CString type = collEl.getChildElement("type").getText();
-			XmlElement valEl = collEl.getChildElement("value");
+			collEl.getChildElement("type", el);
+			CString type = el.getText();
+			XmlElement valEl;
+			collEl.getChildElement("value", valEl);
 			(void)valEl; // XXX
 
 			if(type == "sphere")
@@ -324,27 +329,28 @@ void Model::load(const CString& filename, ResourceInitializer& init)
 		}
 
 		// <modelPatches>
-		XmlElement modelPatchesEl =
-			rootEl.getChildElement("modelPatches");
-		XmlElement modelPatchEl =
-			modelPatchesEl.getChildElement("modelPatch");
+		XmlElement modelPatchesEl;
+		rootEl.getChildElement("modelPatches", modelPatchesEl);
+		XmlElement modelPatchEl;
+		modelPatchesEl.getChildElement("modelPatch", modelPatchEl);
 		do
 		{
-			XmlElement materialEl =
-				modelPatchEl.getChildElement("material");
+			XmlElement materialEl;
+			modelPatchEl.getChildElement("material", materialEl);
 
 			Array<CString, 3> meshesFnames;
 			U meshesCount = 1;
 			ModelPatchBase* patch;
 
 			// Try mesh
-			XmlElement meshEl = modelPatchEl.getChildElementOptional("mesh");
+			XmlElement meshEl;
+			modelPatchEl.getChildElementOptional("mesh", meshEl);
 			if(meshEl)
 			{
-				XmlElement meshEl1 =
-					modelPatchEl.getChildElementOptional("mesh1");
-				XmlElement meshEl2 =
-					modelPatchEl.getChildElementOptional("mesh2");
+				XmlElement meshEl1;
+				modelPatchEl.getChildElementOptional("mesh1", meshEl1);
+				XmlElement meshEl2;
+				modelPatchEl.getChildElementOptional("mesh2", meshEl2);
 
 				meshesFnames[0] = meshEl.getText();
 
@@ -367,12 +373,12 @@ void Model::load(const CString& filename, ResourceInitializer& init)
 			}
 			else
 			{
-				XmlElement bmeshEl =
-					modelPatchEl.getChildElement("bucketMesh");
-				XmlElement bmeshEl1 =
-					modelPatchEl.getChildElementOptional("bucketMesh1");
-				XmlElement bmeshEl2 =
-					modelPatchEl.getChildElementOptional("bucketMesh2");
+				XmlElement bmeshEl;
+				modelPatchEl.getChildElement("bucketMesh", bmeshEl);
+				XmlElement bmeshEl1;
+				modelPatchEl.getChildElementOptional("bucketMesh1", bmeshEl1);
+				XmlElement bmeshEl2;
+				modelPatchEl.getChildElementOptional("bucketMesh2", bmeshEl2);
 
 				meshesFnames[0] = bmeshEl.getText();
 

+ 12 - 6
src/resource/ParticleEmitterResource.cpp

@@ -19,20 +19,22 @@ namespace anki {
 //==============================================================================
 static void xmlReadVec3(const XmlElement& el_, const CString& str, Vec3& out)
 {
-	XmlElement el = el_.getChildElementOptional(str);
+	XmlElement el;
+	el_.getChildElementOptional(str, el);
 
 	if(!el)
 	{
 		return;
 	}
 
-	out = el.getVec3();
+	el.getVec3(out);
 }
 
 //==============================================================================
 static void xmlReadFloat(const XmlElement& el_, const CString& str, F32& out)
 {
-	XmlElement el = el_.getChildElementOptional(str);
+	XmlElement el;
+	el_.getChildElementOptional(str, el);
 
 	if(!el)
 	{
@@ -47,7 +49,8 @@ static void xmlReadFloat(const XmlElement& el_, const CString& str, F32& out)
 //==============================================================================
 static void xmlReadU(const XmlElement& el_, const CString& str, U32& out)
 {
-	XmlElement el = el_.getChildElementOptional(str);
+	XmlElement el;
+	el_.getChildElementOptional(str, el);
 
 	if(!el)
 	{
@@ -104,7 +107,9 @@ void ParticleEmitterResource::load(const CString& filename,
 	{
 		XmlDocument doc;
 		doc.loadFile(filename, init.m_tempAlloc);
-		loadInternal(doc.getChildElement("particleEmitter"), init);
+		XmlElement el;
+		doc.getChildElement("particleEmitter", el);
+		loadInternal(el, init);
 	}
 	catch(std::exception& e)
 	{
@@ -156,7 +161,8 @@ void ParticleEmitterResource::loadInternal(const XmlElement& rootel,
 	xmlReadU(rootel, "usePhysicsEngine", tmp);
 	m_usePhysicsEngine = tmp;
 
-	XmlElement el = rootel.getChildElement("material");
+	XmlElement el;
+	rootel.getChildElement("material", el);
 	m_material.load(el.getText(), &init.m_resources);
 
 	// sanity checks

+ 12 - 7
src/resource/Skeleton.cpp

@@ -24,13 +24,16 @@ void Skeleton::load(const CString& filename, ResourceInitializer& init)
 	XmlDocument doc;
 	doc.loadFile(filename, init.m_tempAlloc);
 
-	XmlElement rootEl = doc.getChildElement("skeleton");
-	XmlElement bonesEl = rootEl.getChildElement("bones");
+	XmlElement rootEl;
+	doc.getChildElement("skeleton", rootEl);
+	XmlElement bonesEl;
+	rootEl.getChildElement("bones", bonesEl);
 
 	// count the bones count
 	U bonesCount = 0;
 
-	XmlElement boneEl = bonesEl.getChildElement("bone");
+	XmlElement boneEl;
+	bonesEl.getChildElement("bone", boneEl);
 
 	do
 	{
@@ -42,19 +45,21 @@ void Skeleton::load(const CString& filename, ResourceInitializer& init)
 	m_bones.resize(bonesCount, Bone(init.m_alloc));
 
 	// Load every bone
-	boneEl = bonesEl.getChildElement("bone");
+	bonesEl.getChildElement("bone", boneEl);
 	bonesCount = 0;
 	do
 	{
 		Bone& bone = m_bones[bonesCount++];
 
 		// <name>
-		XmlElement nameEl = boneEl.getChildElement("name");
+		XmlElement nameEl;
+		boneEl.getChildElement("name", nameEl);
 		bone.m_name = nameEl.getText();
 
 		// <transform>
-		XmlElement trfEl = boneEl.getChildElement("transform");
-		bone.m_transform = trfEl.getMat4();
+		XmlElement trfEl;
+		boneEl.getChildElement("transform", trfEl);
+		trfEl.getMat4(bone.m_transform);
 
 		// Advance 
 		boneEl = boneEl.getNextSiblingElement("bone");