Browse Source

Fixing bugs

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
561361395e

+ 24 - 8
include/anki/resource/MaterialProgramCreator.h

@@ -26,11 +26,12 @@ class MaterialProgramCreator
 {
 {
 public:
 public:
 	using MPString = TempResourceString; 
 	using MPString = TempResourceString; 
-	using MPStringList = StringListBase<TempResourceAllocator<char>>; 
+	using MPStringList = StringListBase<TempResourceAllocator<char>>;
 
 
-	class Input
+	class Input: public NonCopyable
 	{
 	{
 	public:
 	public:
+		TempResourceAllocator<U8> m_alloc;
 		MPString m_name;
 		MPString m_name;
 		MPString m_type;
 		MPString m_type;
 		MPStringList m_value;
 		MPStringList m_value;
@@ -43,22 +44,37 @@ public:
 		GLbitfield m_shaderReferencedMask = 0; ///< Referenced by
 		GLbitfield m_shaderReferencedMask = 0; ///< Referenced by
 		Bool8 m_inBlock = true;
 		Bool8 m_inBlock = true;
 
 
-		void destroy(TempResourceAllocator<U8> alloc)
+		Input()
+		{}
+
+		Input(Input&& b)
+		{
+			move(b);
+		}
+
+		~Input()
+		{
+			m_name.destroy(m_alloc);
+			m_type.destroy(m_alloc);
+			m_value.destroy(m_alloc);
+			m_line.destroy(m_alloc);
+		}
+
+		Input& operator=(Input&& b)
 		{
 		{
-			m_name.destroy(alloc);
-			m_type.destroy(alloc);
-			m_value.destroy(alloc);
-			m_line.destroy(alloc);
+			move(b);
+			return *this;
 		}
 		}
 
 
 		void move(Input& b)
 		void move(Input& b)
 		{
 		{
+			m_alloc = std::move(b.m_alloc);
 			m_name = std::move(b.m_name);
 			m_name = std::move(b.m_name);
 			m_type = std::move(b.m_type);
 			m_type = std::move(b.m_type);
 			m_value = std::move(b.m_value);
 			m_value = std::move(b.m_value);
 			m_constant = b.m_constant;
 			m_constant = b.m_constant;
 			m_arraySize = b.m_arraySize;
 			m_arraySize = b.m_arraySize;
-			m_line = std::move(m_line);
+			m_line = std::move(b.m_line);
 			m_shaderDefinedMask = b.m_shaderDefinedMask;
 			m_shaderDefinedMask = b.m_shaderDefinedMask;
 			m_shaderReferencedMask = b.m_shaderReferencedMask;
 			m_shaderReferencedMask = b.m_shaderReferencedMask;
 			m_inBlock = b.m_inBlock;
 			m_inBlock = b.m_inBlock;

+ 38 - 28
include/anki/scene/SceneGraph.h

@@ -174,34 +174,7 @@ public:
 	/// Create a new SceneNode
 	/// Create a new SceneNode
 	template<typename Node, typename... Args>
 	template<typename Node, typename... Args>
 	ANKI_USE_RESULT Error newSceneNode(
 	ANKI_USE_RESULT Error newSceneNode(
-		const CString& name, Node*& node, Args&&... args)
-	{
-		Error err = ErrorCode::NONE;
-		SceneAllocator<Node> al = m_alloc;
-
-		node = al.template newInstance<Node>(this);
-		if(node)
-		{
-			err = node->create(name, std::forward<Args>(args)...);
-		}
-		else
-		{
-			err = ErrorCode::OUT_OF_MEMORY;
-		}
-
-		if(!err)
-		{
-			err = registerNode(node);
-		}
-
-		if(err && node)
-		{
-			al.deleteInstance(node);
-			node = nullptr;
-		}
-
-		return err;
-	}
+		const CString& name, Node*& node, Args&&... args);
 
 
 	/// Delete a scene node. It actualy marks it for deletion
 	/// Delete a scene node. It actualy marks it for deletion
 	void deleteSceneNode(SceneNode* node)
 	void deleteSceneNode(SceneNode* node)
@@ -263,6 +236,43 @@ private:
 	void deleteNodesMarkedForDeletion();
 	void deleteNodesMarkedForDeletion();
 };
 };
 
 
+//==============================================================================
+template<typename Node, typename... Args>
+inline Error SceneGraph::newSceneNode(
+	const CString& name, Node*& node, Args&&... args)
+{
+	Error err = ErrorCode::NONE;
+	SceneAllocator<Node> al = m_alloc;
+
+	node = al.template newInstance<Node>(this);
+	if(node)
+	{
+		err = node->create(name, std::forward<Args>(args)...);
+	}
+	else
+	{
+		err = ErrorCode::OUT_OF_MEMORY;
+	}
+
+	if(!err)
+	{
+		err = registerNode(node);
+	}
+
+	if(err)
+	{
+		ANKI_LOGE("Failed to create scene node: %s", 
+			(name.isEmpty()) ? "unnamed" : &name[0]);
+
+		if(node)
+		{
+			al.deleteInstance(node);
+			node = nullptr;
+		}
+	}
+
+	return err;
+}
 /// @}
 /// @}
 
 
 } // end namespace anki
 } // end namespace anki

+ 19 - 7
include/anki/util/Allocator.h

@@ -189,6 +189,7 @@ public:
 	/// Call destructor
 	/// Call destructor
 	void destroy(pointer p)
 	void destroy(pointer p)
 	{
 	{
+		ANKI_ASSERT(p != nullptr);
 		p->~T();
 		p->~T();
 	}
 	}
 
 
@@ -196,6 +197,7 @@ public:
 	template<typename U>
 	template<typename U>
 	void destroy(U* p)
 	void destroy(U* p)
 	{
 	{
+		ANKI_ASSERT(p != nullptr);
 		p->~U();
 		p->~U();
 	}
 	}
 
 
@@ -282,8 +284,11 @@ public:
 	{
 	{
 		typename rebind<U>::other alloc(*this);
 		typename rebind<U>::other alloc(*this);
 
 
-		alloc.destroy(x);
-		alloc.deallocate(x, 1);
+		if(x != nullptr)
+		{
+			alloc.destroy(x);
+			alloc.deallocate(x, 1);
+		}
 	}
 	}
 
 
 	/// Call the destructor and deallocate an array of objects
 	/// Call the destructor and deallocate an array of objects
@@ -293,13 +298,20 @@ public:
 	{
 	{
 		typename rebind<U>::other alloc(*this);
 		typename rebind<U>::other alloc(*this);
 
 
-		// Call the destructors
-		for(size_type i = 0; i < n; i++)
+		if(x != nullptr)
 		{
 		{
-			alloc.destroy(&x[i]);
-		}
+			// Call the destructors
+			for(size_type i = 0; i < n; i++)
+			{
+				alloc.destroy(&x[i]);
+			}
 
 
-		alloc.deallocate(x, n);
+			alloc.deallocate(x, n);
+		}
+		else
+		{
+			ANKI_ASSERT(n == 0);
+		}
 	}
 	}
 
 
 private:
 private:

+ 5 - 0
include/anki/util/StdTypes.h

@@ -143,6 +143,11 @@ public:
 	{
 	{
 		return m_code;
 		return m_code;
 	}
 	}
+
+	I32 _getCodeInt() const
+	{
+		return static_cast<I32>(m_code);
+	}
 	/// @}
 	/// @}
 
 
 private:
 private:

+ 1 - 5
src/gl/GlSync.cpp

@@ -11,11 +11,7 @@ namespace anki {
 //==============================================================================
 //==============================================================================
 void GlClientSync::wait()
 void GlClientSync::wait()
 {
 {
-	Bool timeout = m_barrier.wait();
-	if(timeout)
-	{
-		ANKI_LOGW("Sync timed out. Probably because of exception");
-	}
+	m_barrier.wait();
 }
 }
 
 
 } // end namespace anki
 } // end namespace anki

+ 19 - 10
src/resource/MaterialProgramCreator.cpp

@@ -7,7 +7,6 @@
 #include "anki/util/Assert.h"
 #include "anki/util/Assert.h"
 #include "anki/misc/Xml.h"
 #include "anki/misc/Xml.h"
 #include "anki/util/Logger.h"
 #include "anki/util/Logger.h"
-
 #include <algorithm>
 #include <algorithm>
 
 
 namespace anki {
 namespace anki {
@@ -81,7 +80,12 @@ MaterialProgramCreator::MaterialProgramCreator(TempResourceAllocator<U8>& alloc)
 //==============================================================================
 //==============================================================================
 MaterialProgramCreator::~MaterialProgramCreator()
 MaterialProgramCreator::~MaterialProgramCreator()
 {
 {
-	for(auto& it : m_inputs)
+	for(auto& it : m_source)
+	{
+		it.destroy(m_alloc);
+	}
+
+	for(auto& it : m_sourceBaked)
 	{
 	{
 		it.destroy(m_alloc);
 		it.destroy(m_alloc);
 	}
 	}
@@ -218,12 +222,12 @@ Error MaterialProgramCreator::parseProgramTag(
 	{
 	{
 		if(!in.m_inBlock && (in.m_shaderDefinedMask & glshaderbit))
 		if(!in.m_inBlock && (in.m_shaderDefinedMask & glshaderbit))
 		{
 		{
-			ANKI_ASSERT(lines.pushBackSprintf(m_alloc, &in.m_line[0]));
+			ANKI_CHECK(lines.pushBackSprintf(m_alloc, &in.m_line[0]));
 		}
 		}
 	}
 	}
 
 
 	// <operations></operations>
 	// <operations></operations>
-	ANKI_ASSERT(lines.pushBackSprintf(m_alloc, "\nvoid main()\n{"));
+	ANKI_CHECK(lines.pushBackSprintf(m_alloc, "\nvoid main()\n{"));
 
 
 	XmlElement opsEl;
 	XmlElement opsEl;
 	ANKI_CHECK(programEl.getChildElement("operations", opsEl));
 	ANKI_CHECK(programEl.getChildElement("operations", opsEl));
@@ -233,7 +237,7 @@ Error MaterialProgramCreator::parseProgramTag(
 	{
 	{
 		MPString out;
 		MPString out;
 		ANKI_CHECK(parseOperationTag(opEl, glshader, glshaderbit, out));
 		ANKI_CHECK(parseOperationTag(opEl, glshader, glshaderbit, out));
-		ANKI_ASSERT(lines.pushBackSprintf(m_alloc, &out[0]));
+		ANKI_CHECK(lines.pushBackSprintf(m_alloc, &out[0]));
 		out.destroy(m_alloc);
 		out.destroy(m_alloc);
 
 
 		// Advance
 		// Advance
@@ -270,6 +274,7 @@ Error MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 	do
 	do
 	{
 	{
 		Input inpvar;
 		Input inpvar;
+		inpvar.m_alloc = m_alloc;
 
 
 		// <name>
 		// <name>
 		ANKI_CHECK(inputEl.getChildElement("name", el));
 		ANKI_CHECK(inputEl.getChildElement("name", el));
@@ -443,7 +448,7 @@ Error MaterialProgramCreator::parseInputsTag(const XmlElement& programEl)
 		{
 		{
 			// Handle consts
 			// Handle consts
 
 
-			if(!inpvar.m_value.isEmpty())
+			if(inpvar.m_value.isEmpty())
 			{
 			{
 				ANKI_LOGE("Empty value and const is illogical");
 				ANKI_LOGE("Empty value and const is illogical");
 				return ErrorCode::USER_DATA;
 				return ErrorCode::USER_DATA;
@@ -543,7 +548,7 @@ Error MaterialProgramCreator::parseOperationTag(
 
 
 			// The argument should be an input variable or an outXX
 			// The argument should be an input variable or an outXX
 			if(!(input != nullptr 
 			if(!(input != nullptr 
-				|| std::memcmp(&arg[0], "out", 3) == 0))
+				|| std::memcmp(&arg[0], OUT, 3) == 0))
 			{
 			{
 				ANKI_LOGE("Incorrect argument: %s", &arg[0]);
 				ANKI_LOGE("Incorrect argument: %s", &arg[0]);
 				return ErrorCode::USER_DATA;
 				return ErrorCode::USER_DATA;
@@ -608,7 +613,7 @@ Error MaterialProgramCreator::parseOperationTag(
 		ANKI_CHECK(retTypeEl.getText(cstr));
 		ANKI_CHECK(retTypeEl.getText(cstr));
 		ANKI_CHECK(lines.pushBackSprintf(m_alloc,
 		ANKI_CHECK(lines.pushBackSprintf(m_alloc,
 			"#\tdefine out%u_DEFINED\n"
 			"#\tdefine out%u_DEFINED\n"
-			"\tout%u = ", id));
+			"\t%s out%u = ", id, &cstr[0], id));
 	}
 	}
 	else
 	else
 	{
 	{
@@ -619,10 +624,14 @@ Error MaterialProgramCreator::parseOperationTag(
 	MPString argsStr;
 	MPString argsStr;
 	MPString::ScopeDestroyer argsStrd(&argsStr, m_alloc);
 	MPString::ScopeDestroyer argsStrd(&argsStr, m_alloc);
 
 
-	ANKI_CHECK(argsList.join(m_alloc, ", ", argsStr));
+	if(!argsList.isEmpty())
+	{
+		ANKI_CHECK(argsList.join(m_alloc, ", ", argsStr));
+	}
 
 
 	ANKI_CHECK(lines.pushBackSprintf(m_alloc, "%s(%s);\n#endif",
 	ANKI_CHECK(lines.pushBackSprintf(m_alloc, "%s(%s);\n#endif",
-		&funcName[0], &argsStr[0]));
+		&funcName[0], 
+		(argsStr.isEmpty()) ? "" : &argsStr[0]));
 
 
 	// Bake final string
 	// Bake final string
 	ANKI_CHECK(lines.join(m_alloc, " ", out));
 	ANKI_CHECK(lines.join(m_alloc, " ", out));

+ 1 - 0
src/resource/ProgramResource.cpp

@@ -123,6 +123,7 @@ Error ProgramResource::createToCache(
 	ANKI_CHECK(f.open(newFilename.toCString(), File::OpenFlag::WRITE));
 	ANKI_CHECK(f.open(newFilename.toCString(), File::OpenFlag::WRITE));
 	ANKI_CHECK(f.writeText("%s\n", &srcfull[0]));
 	ANKI_CHECK(f.writeText("%s\n", &srcfull[0]));
 
 
+	out = std::move(newFilename);
 	return err;
 	return err;
 }
 }
 
 

+ 11 - 3
testapp/Main.cpp

@@ -554,10 +554,18 @@ int main(int argc, char* argv[])
 {
 {
 	Error err = ErrorCode::NONE;
 	Error err = ErrorCode::NONE;
 
 
-	initSubsystems(argc, argv);
-	init();
+	err = initSubsystems(argc, argv);
+
+	if(!err)
+	{
+		err = init();
+	}
+
+	if(!err)
+	{
+		err = app->mainLoop(mainLoopExtra, nullptr);
+	}
 
 
-	err = app->mainLoop(mainLoopExtra, nullptr);
 	if(err)
 	if(err)
 	{
 	{
 		ANKI_LOGE("Error reported. See previous messages");
 		ANKI_LOGE("Error reported. See previous messages");