Browse Source

Writing tests

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
e9c8fe332b

+ 5 - 4
include/anki/gl/GlCommandBuffer.h

@@ -41,7 +41,8 @@ public:
 	TAlloc m_alloc;
 
 	GlDeleteObjectCommand(T* ptr, TAlloc alloc)
-		: m_ptr(ptr), m_alloc(alloc)
+	:	m_ptr(ptr), 
+		m_alloc(alloc)
 	{
 		ANKI_ASSERT(m_ptr);
 	}
@@ -52,8 +53,8 @@ public:
 	}
 };
 
-/// Command buffer initialization hints. They are used to optimize the allocators
-/// of a command buffer
+/// Command buffer initialization hints. They are used to optimize the 
+/// allocators of a command buffer
 class GlCommandBufferInitHints
 {
 	friend class GlCommandBuffer;
@@ -94,7 +95,7 @@ public:
 		return m_alloc;
 	}
 
-	GlGlobalHeapAllocator<U8> getGlobalAllocator() const;
+	GlAllocator<U8> getGlobalAllocator() const;
 
 	GlQueue& getQueue()
 	{

+ 1 - 1
include/anki/gl/GlCommandBufferHandle.h

@@ -151,7 +151,7 @@ public:
 		return _get().getAllocator();
 	}
 
-	GlGlobalHeapAllocator<U8> _getGlobalAllocator() const
+	GlAllocator<U8> _getGlobalAllocator() const
 	{
 		return _get().getGlobalAllocator();
 	}

+ 1 - 1
include/anki/gl/GlCommon.h

@@ -45,7 +45,7 @@ using GlCommandBufferAllocator = ChainAllocator<T>;
 
 /// The type of the allocator for heap allocations
 template<typename T>
-using GlGlobalHeapAllocator = HeapAllocator<T>;
+using GlAllocator = HeapAllocator<T>;
 
 /// Texture filtering method
 enum class GlTextureFilter: U8

+ 1 - 1
include/anki/gl/GlContainerHandle.h

@@ -30,7 +30,7 @@ protected:
 
 		if(state == GlHandleState::TO_BE_CREATED)
 		{
-			Base::_getManager()._getQueue().syncClientServer();
+			Base::_getDevice()._getQueue().syncClientServer();
 			ANKI_ASSERT(Base::_getState() > GlHandleState::TO_BE_CREATED);
 		}
 	}

+ 11 - 31
include/anki/gl/GlHandle.h

@@ -79,7 +79,7 @@ public:
 			Block* blk = alloc.template newInstance<Block>();
 
 			blk->m_state = GlHandleState::NEW;
-			blk->m_manager = manager;
+			blk->m_gl = manager;
 			blk->m_alloc = alloc;
 			blk->m_del = del;
 
@@ -110,32 +110,12 @@ public:
 		*this = b;
 	}
 
-	GlHandle(GlHandle&& b)
-	:	GlHandle()
-	{
-		*this = std::move(b);
-	}
-
 	~GlHandle()
 	{
 		reset();
 	}
 	/// @}
 
-	/// Move
-	GlHandle& operator=(GlHandle&& b)
-	{
-		reset();
-	
-		if(b.m_cb)
-		{
-			m_cb = b.m_cb;
-			b.m_cb = nullptr;
-		}
-
-		return *this;
-	}
-
 	/// Copy
 	GlHandle& operator=(const GlHandle& b)
 	{
@@ -230,10 +210,10 @@ public:
 		return m_cb->getStateAtomically(&newVal);
 	}
 
-	GlDevice& _getManager() const
+	GlDevice& _getDevice() const
 	{
-		ANKI_ASSERT(m_cb != nullptr && m_cb->getManager() != nullptr);
-		return *m_cb->getManager(); 
+		ANKI_ASSERT(m_cb != nullptr && m_cb->getDevice() != nullptr);
+		return *m_cb->getDevice(); 
 	}
 
 private:
@@ -244,19 +224,19 @@ private:
 	{
 	public:
 		Y* m_ptr;
-		Atomic<I32> m_refcount;
+		AtomicI32 m_refcount;
 
 		virtual ~CtrlBlockBase()
 		{}
 		
-		/// Destroy the object in m_ptr
+		/// Delete the m_ptr
 		virtual void deletePtr() = 0;
 
 		/// Delete the block itself
 		virtual void deleteSelf() = 0;
 
 		/// The container handles want the manager
-		virtual GlDevice* getManager() const
+		virtual GlDevice* getDevice() const
 		{
 			return nullptr;
 		}
@@ -310,14 +290,14 @@ private:
 		YDeleter m_del;
 
 		/// @note Its mutable because we want read/write access to it
-		mutable GlDevice* m_manager; 
+		mutable GlDevice* m_gl; 
 
 		Atomic<GlHandleState> m_state;
 		
 		void deletePtr()
 		{
 			// Delete object
-			m_del(Base::m_ptr, m_alloc, getManager());
+			m_del(Base::m_ptr, m_alloc, getDevice());
 		}
 
 		void deleteSelf()
@@ -326,9 +306,9 @@ private:
 			m_alloc.deleteInstance(this);
 		}
 
-		GlDevice* getManager() const override
+		GlDevice* getDevice() const override
 		{
-			return m_manager;
+			return m_gl;
 		}
 
 		GlHandleState getStateAtomically(GlHandleState* newVal) override

+ 6 - 6
include/anki/gl/GlProgram.h

@@ -23,13 +23,13 @@ class GlProgramData: public NonCopyable
 {
 public:
 	template<typename T>
-	using ProgramVector = Vector<T, GlGlobalHeapAllocator<T>>;
+	using ProgramVector = Vector<T, GlAllocator<T>>;
 
 	template<typename T>
 	using ProgramDictionary = 
-		Dictionary<T, GlGlobalHeapAllocator<std::pair<CString, T>>>;
+		Dictionary<T, GlAllocator<std::pair<CString, T>>>;
 
-	GlProgramData(const GlGlobalHeapAllocator<U8>& alloc)
+	GlProgramData(const GlAllocator<U8>& alloc)
 	:	m_variables(alloc), 
 		m_variablesDict(10, DictionaryHasher(), DictionaryEqual(), alloc), 
 		m_blocks(alloc), 
@@ -88,7 +88,7 @@ public:
 	GlProgram(
 		GLenum shaderType, 
 		const CString& source, 
-		const GlGlobalHeapAllocator<U8>& alloc, 
+		const GlAllocator<U8>& alloc, 
 		const CString& cacheDir)
 	:	m_data(nullptr)
 	{
@@ -133,9 +133,9 @@ private:
 	GlProgramData* m_data;
 
 	void create(GLenum type, const CString& source, 
-		const GlGlobalHeapAllocator<U8>& alloc, const CString& cacheDir);
+		const GlAllocator<U8>& alloc, const CString& cacheDir);
 	void createInternal(GLenum type, const CString& source, 
-		const GlGlobalHeapAllocator<U8>& alloc, const CString& cacheDir);
+		const GlAllocator<U8>& alloc, const CString& cacheDir);
 	void destroy();
 
 	/// Query the program for blocks

+ 1 - 1
include/anki/gl/GlProgramHandle.h

@@ -26,7 +26,7 @@ public:
 
 	// Re-define it here
 	template<typename T>
-	using ProgramVector = Vector<T, GlGlobalHeapAllocator<T>>;
+	using ProgramVector = Vector<T, GlAllocator<T>>;
 
 	/// @name Contructors/Destructor
 	/// @{

+ 2 - 2
include/anki/gl/GlTexture.h

@@ -49,7 +49,7 @@ public:
 	{}
 
 	GlTexture(const Initializer& init, 
-		GlGlobalHeapAllocator<U8>& alloc)
+		GlAllocator<U8>& alloc)
 	{
 		create(init, alloc);
 	}
@@ -155,7 +155,7 @@ private:
 	U8 m_samples;
 
 	/// Create a texture
-	void create(const Initializer& init, GlGlobalHeapAllocator<U8>& alloc);
+	void create(const Initializer& init, GlAllocator<U8>& alloc);
 
 	void destroy();
 

+ 12 - 17
include/anki/resource/DummyRsrc.h

@@ -6,6 +6,8 @@
 #ifndef ANKI_RESOURCE_DUMMY_RSRC_H
 #define ANKI_RESOURCE_DUMMY_RSRC_H
 
+#include "anki/resource/Common.h"
+
 namespace anki {
 
 /// @addtogroup resource_private
@@ -16,34 +18,27 @@ class DummyRsrc
 {
 public:
 	DummyRsrc()
-	{
-		++mem;
-		loaded = false;
-	}
+	{}
 
 	~DummyRsrc()
 	{
-		--mem;
-		if(loaded)
+		if(m_memory)
 		{
-			--mem;
+			m_alloc.deallocate(m_memory, 128);
 		}
 	}
 
-	void load(const char* filename)
-	{
-		++mem;
-		loaded = true;
-	}
-
-	static int getMem()
+	void load(const CString& filename, ResourceInitializer& init)
 	{
-		return mem;
+		m_alloc = init.m_alloc;
+		m_memory = m_alloc.allocate(128);
+		void* tempMem = init.m_tempAlloc.allocate(128);
+		(void)tempMem;
 	}
 
 private:
-	static int mem;
-	bool loaded;
+	void* m_memory = nullptr;
+	HeapAllocator<U8> m_alloc;
 };
 
 /// @}

+ 3 - 1
include/anki/resource/ResourceManager.h

@@ -33,6 +33,7 @@ ANKI_RESOURCE(BucketMesh, BucketMeshResourcePointer)
 ANKI_RESOURCE(Skeleton, SkeletonResourcePointer)
 ANKI_RESOURCE(ParticleEmitterResource, ParticleEmitterResourcePointer)
 ANKI_RESOURCE(Model, ModelResourcePointer)
+ANKI_RESOURCE(DummyRsrc, DummyResourcePointer)
 
 #undef ANKI_RESOURCE
 
@@ -131,7 +132,8 @@ class ResourceManager:
 	ANKI_RESOURCE(BucketMesh),
 	ANKI_RESOURCE(Skeleton),
 	ANKI_RESOURCE(ParticleEmitterResource),
-	ANKI_RESOURCE(Model)
+	ANKI_RESOURCE(Model),
+	ANKI_RESOURCE(DummyRsrc)
 {
 public:
 	class Initializer

+ 0 - 14
include/anki/resource/ResourcePointer.h

@@ -38,12 +38,6 @@ public:
 		copy(b);
 	}
 
-	/// Move contructor
-	ResourcePointer(ResourcePointer&& b)
-	{
-		*this = std::move(b);
-	}
-
 	/// Construct and load
 	ResourcePointer(const CString& filename, TResourceManager* resources)
 	{
@@ -110,14 +104,6 @@ public:
 		return *this;
 	}
 
-	/// Move
-	ResourcePointer& operator=(ResourcePointer&& b)
-	{
-		m_cb = b.m_cb;
-		b.m_cb = nullptr;
-		return *this;
-	}
-
 	Bool operator==(const ResourcePointer& b) const
 	{
 		ANKI_ASSERT(m_cb != nullptr);

+ 7 - 2
include/anki/resource/ResourcePointer.inl.h

@@ -28,6 +28,8 @@ void ResourcePointer<T, TResourceManager>::load(
 			sizeof(ControlBlock) + len, &alignment));
 		resources->_getAllocator().construct(m_cb);
 
+		m_cb->m_resources = resources;
+
 		// Populate the m_cb
 		try
 		{
@@ -37,10 +39,13 @@ void ResourcePointer<T, TResourceManager>::load(
 				*resources);
 
 			m_cb->m_resource.load(filename, init);
+
+			resources->_getTempAllocator().getMemoryPool().reset();
 		}
 		catch(const std::exception& e)
 		{
-			m_cb->m_resources->_getAllocator().deleteInstance(m_cb);	
+			resources->_getAllocator().deleteInstance(m_cb);
+			throw ANKI_EXCEPTION("Loading failed: %s", &filename[0]) << e;
 		}
 
 		m_cb->m_resources = resources;
@@ -81,7 +86,7 @@ void ResourcePointer<T, TResourceManager>::copy(const ResourcePointer& b)
 {
 	reset();
 	
-	if(b.m_cb == nullptr)
+	if(b.m_cb != nullptr)
 	{
 		auto count = b.m_cb->m_refcount.fetch_add(1);
 		ANKI_ASSERT(count > 0);

+ 3 - 4
include/anki/util/File.h

@@ -91,13 +91,12 @@ public:
 
 	/// Read all the contents of a text file
 	/// If the file is not rewined it will probably fail
-	template<typename TContainer>
-	void readAllText(TContainer& out)
+	template<typename TAlloc>
+	void readAllText(StringBase<TAlloc>& out)
 	{
 		PtrSize size = getSize();
-		out.resize(size + 1);
+		out.resize(size, '\0');
 		read(&out[0], size);
-		out[size] = '\0';
 	}
 
 	/// Read 32bit unsigned integer. Set the endianness if the file's 

+ 3 - 1
include/anki/util/String.h

@@ -483,7 +483,9 @@ public:
 	PtrSize getLength() const noexcept
 	{
 		auto size = m_data.size();
-		return (size != 0) ? (size - 1) : 0;
+		auto out = (size != 0) ? (size - 1) : 0;
+		ANKI_ASSERT(std::strlen(&m_data[0]) == out);
+		return out;
 	}
 
 	/// Return the allocator

+ 2 - 7
src/core/App.cpp

@@ -58,13 +58,14 @@ void App::swapWindow(void* window)
 //==============================================================================
 void App::init(const ConfigSet& config)
 {
+	initDirs();
+
 	// Logger
 	LoggerSingleton::init(
 		Logger::InitFlags::WITH_SYSTEM_MESSAGE_HANDLER, m_heapAlloc,
 		&m_cacheDir[0]);
 
 	printAppInfo();
-	initDirs();
 
 	m_timerTick = 1.0 / 60.0; // in sec. 1.0 / period
 
@@ -132,7 +133,6 @@ void App::initDirs()
 	String settingsDir = home + "/.anki";
 	if(!directoryExists(settingsDir.toCString()))
 	{
-		ANKI_LOGI("Creating settings dir: %s", &settingsDir[0]);
 		createDirectory(settingsDir.toCString());
 	}
 
@@ -140,11 +140,9 @@ void App::initDirs()
 	m_cacheDir = settingsDir + "/cache";
 	if(directoryExists(m_cacheDir.toCString()))
 	{
-		ANKI_LOGI("Deleting dir: %s", &m_cacheDir[0]);
 		removeDirectory(m_cacheDir.toCString());
 	}
 
-	ANKI_LOGI("Creating cache dir: %s", &m_cacheDir[0]);
 	createDirectory(m_cacheDir.toCString());
 #else
 	//ANKI_ASSERT(gAndroidApp);
@@ -155,7 +153,6 @@ void App::initDirs()
 	settingsDir = String("/sdcard/.anki/");
 	if(!directoryExists(settingsDir.c_str()))
 	{
-		ANKI_LOGI("Creating settings dir: %s", settingsDir.c_str());
 		createDirectory(settingsDir.c_str());
 	}
 
@@ -163,11 +160,9 @@ void App::initDirs()
 	cacheDir = settingsDir + "/cache";
 	if(directoryExists(cacheDir.c_str()))
 	{
-		ANKI_LOGI("Deleting dir: %s", cacheDir.c_str());
 		removeDirectory(cacheDir.c_str());
 	}
 
-	ANKI_LOGI("Creating cache dir: %s", cacheDir.c_str());
 	createDirectory(cacheDir.c_str());
 #endif
 }

+ 1 - 0
src/core/Config.cpp

@@ -88,6 +88,7 @@ Config::Config()
 	//
 	newOption("glminor", 4);
 	newOption("glmajor", 4);
+	newOption("fullscreen", false);
 }
 
 //==============================================================================

+ 4 - 4
src/gl/GlBufferHandle.cpp

@@ -72,10 +72,10 @@ GlBufferHandle::GlBufferHandle(GlCommandBufferHandle& commands,
 {
 	ANKI_ASSERT(!isCreated());
 
-	using Alloc = GlGlobalHeapAllocator<GlBuffer>;
+	using Alloc = GlAllocator<GlBuffer>;
 
 	using DeleteCommand = 
-		GlDeleteObjectCommand<GlBuffer, GlGlobalHeapAllocator<U8>>;
+		GlDeleteObjectCommand<GlBuffer, GlAllocator<U8>>;
 
 	using Deleter = GlHandleDeferredDeleter<GlBuffer, Alloc, DeleteCommand>;
 
@@ -96,10 +96,10 @@ GlBufferHandle::GlBufferHandle(GlCommandBufferHandle& commands,
 {
 	ANKI_ASSERT(!isCreated());
 
-	using Alloc = GlGlobalHeapAllocator<GlBuffer>;
+	using Alloc = GlAllocator<GlBuffer>;
 
 	using DeleteCommand = 
-		GlDeleteObjectCommand<GlBuffer, GlGlobalHeapAllocator<U8>>;
+		GlDeleteObjectCommand<GlBuffer, GlAllocator<U8>>;
 
 	using Deleter = GlHandleDeferredDeleter<GlBuffer, Alloc, DeleteCommand>;
 

+ 1 - 1
src/gl/GlCommandBuffer.cpp

@@ -77,7 +77,7 @@ void GlCommandBuffer::destroy()
 }
 
 //==============================================================================
-GlGlobalHeapAllocator<U8> GlCommandBuffer::getGlobalAllocator() const
+GlAllocator<U8> GlCommandBuffer::getGlobalAllocator() const
 {
 	return m_server->getDevice()._getAllocator();
 }

+ 6 - 5
src/gl/GlCommandBufferHandle.cpp

@@ -35,7 +35,7 @@ namespace anki {
 	public: \
 		type_ m_value; \
 		Command(type_ v) \
-			: m_value(v) \
+		:	m_value(v) \
 		{} \
 		void operator()(GlCommandBuffer*) \
 		{ \
@@ -98,7 +98,7 @@ namespace anki {
 	public: \
 		Bool8 m_enable; \
 		Command(Bool enable) \
-			: m_enable(enable) \
+		:	m_enable(enable) \
 		{} \
 		void operator()(GlCommandBuffer*) \
 		{ \
@@ -125,7 +125,7 @@ GlCommandBufferHandle::GlCommandBufferHandle(GlDevice* gl,
 	ANKI_ASSERT(!isCreated());
 	ANKI_ASSERT(gl);
 
-	using Alloc = GlGlobalHeapAllocator<GlCommandBuffer>;
+	using Alloc = GlAllocator<GlCommandBuffer>;
 	Alloc alloc = gl->_getAllocator();
 
 	*static_cast<Base*>(this) = Base(
@@ -151,7 +151,8 @@ void GlCommandBufferHandle::pushBackUserCommand(
 		void* m_userData;
 
 		Command(UserCallback callback, void* userData)
-			: m_callback(callback), m_userData(userData)
+		:	m_callback(callback), 
+			m_userData(userData)
 		{
 			ANKI_ASSERT(m_callback);
 		}
@@ -175,7 +176,7 @@ void GlCommandBufferHandle::pushBackOtherCommandBuffer(
 		GlCommandBufferHandle m_commands;
 
 		Command(GlCommandBufferHandle& commands)
-			: m_commands(commands)
+		:	m_commands(commands)
 		{}
 
 		void operator()(GlCommandBuffer*)

+ 1 - 1
src/gl/GlFramebufferHandle.cpp

@@ -57,7 +57,7 @@ GlFramebufferHandle::GlFramebufferHandle(
 		}
 	};
 
-	using Alloc = GlGlobalHeapAllocator<GlFramebuffer>;
+	using Alloc = GlAllocator<GlFramebuffer>;
 	using DeleteCommand = GlDeleteObjectCommand<GlFramebuffer, Alloc>;
 	using Deleter = 
 		GlHandleDeferredDeleter<GlFramebuffer, Alloc, DeleteCommand>;

+ 3 - 3
src/gl/GlProgram.cpp

@@ -291,7 +291,7 @@ GlProgram& GlProgram::operator=(GlProgram&& b)
 
 //==============================================================================
 void GlProgram::create(GLenum type, const CString& source, 
-	const GlGlobalHeapAllocator<U8>& alloc, const CString& cacheDir)
+	const GlAllocator<U8>& alloc, const CString& cacheDir)
 {
 	try
 	{
@@ -306,12 +306,12 @@ void GlProgram::create(GLenum type, const CString& source,
 
 //==============================================================================
 void GlProgram::createInternal(GLenum type, const CString& source, 
-	const GlGlobalHeapAllocator<U8>& alloc_, const CString& cacheDir)
+	const GlAllocator<U8>& alloc_, const CString& cacheDir)
 {
 	ANKI_ASSERT(source);
 	ANKI_ASSERT(!isCreated() && m_data == nullptr);
 
-	GlGlobalHeapAllocator<U8> alloc = alloc_;
+	GlAllocator<U8> alloc = alloc_;
 	m_data = alloc.newInstance<GlProgramData>(alloc);
 	m_type = type;
 

+ 1 - 1
src/gl/GlProgramHandle.cpp

@@ -49,7 +49,7 @@ GlProgramHandle::GlProgramHandle()
 GlProgramHandle::GlProgramHandle(GlCommandBufferHandle& commands, 
 	GLenum type, const GlClientBufferHandle& source)
 {
-	using Alloc = GlGlobalHeapAllocator<GlProgram>;
+	using Alloc = GlAllocator<GlProgram>;
 	using DeleteCommand = GlDeleteObjectCommand<GlProgram, Alloc>;
 	using Deleter = GlHandleDeferredDeleter<GlProgram, Alloc, DeleteCommand>;
 

+ 1 - 1
src/gl/GlProgramPipelineHandle.cpp

@@ -67,7 +67,7 @@ void GlProgramPipelineHandle::commonConstructor(
 		}
 	};
 
-	using Alloc = GlGlobalHeapAllocator<GlProgramPipeline>;
+	using Alloc = GlAllocator<GlProgramPipeline>;
 	using DeleteCommand = GlDeleteObjectCommand<GlProgramPipeline, Alloc>;
 	using Deleter = 
 		GlHandleDeferredDeleter<GlProgramPipeline, Alloc, DeleteCommand>;

+ 1 - 1
src/gl/GlSyncHandles.cpp

@@ -41,7 +41,7 @@ GlClientSyncHandle::GlClientSyncHandle(GlCommandBufferHandle& commands)
 	auto alloc = commands._getGlobalAllocator();
 
 	using Deleter = 
-		GlHandleDefaultDeleter<GlClientSync, GlGlobalHeapAllocator<U8>>;
+		GlHandleDefaultDeleter<GlClientSync, GlAllocator<U8>>;
 
 	*static_cast<Base*>(this) = Base(
 		&commands._getQueue().getDevice(), alloc, Deleter());

+ 2 - 2
src/gl/GlTexture.cpp

@@ -67,7 +67,7 @@ GlTexture& GlTexture::operator=(GlTexture&& b)
 
 //==============================================================================
 void GlTexture::create(const Initializer& init, 
-	GlGlobalHeapAllocator<U8>& alloc)
+	GlAllocator<U8>& alloc)
 {
 	// Sanity checks
 	//
@@ -167,7 +167,7 @@ void GlTexture::create(const Initializer& init,
 				ANKI_ASSERT(m_depth > 0);
 
 				// Gather the data
-				Vector<U8, GlGlobalHeapAllocator<U8>> data(alloc);
+				Vector<U8, GlAllocator<U8>> data(alloc);
 
 				// Check if there are data
 				if(init.m_data[level][0].m_ptr != nullptr)

+ 2 - 2
src/gl/GlTextureHandle.cpp

@@ -93,7 +93,7 @@ GlTextureHandle::GlTextureHandle(
 
 	ANKI_ASSERT(!isCreated());
 
-	using Alloc = GlGlobalHeapAllocator<GlTexture>;
+	using Alloc = GlAllocator<GlTexture>;
 
 	using DeleteCommand = 
 		GlDeleteObjectCommand<GlTexture, Alloc>;
@@ -268,7 +268,7 @@ GlSamplerHandle::GlSamplerHandle(GlCommandBufferHandle& commands)
 		}
 	};
 
-	using Alloc = GlGlobalHeapAllocator<GlSampler>;
+	using Alloc = GlAllocator<GlSampler>;
 
 	using DeleteCommand = GlDeleteObjectCommand<GlSampler, Alloc>;
 

+ 0 - 5
src/resource/DummyRsrc.cpp

@@ -5,11 +5,6 @@
 
 #include "anki/resource/DummyRsrc.h"
 
-
 namespace anki {
 
-
-int DummyRsrc::mem = 0;
-
-
 } // end namespace

+ 4 - 2
src/resource/ResourceManager.cpp

@@ -8,6 +8,7 @@
 #include "anki/resource/Material.h"
 #include "anki/resource/Mesh.h"
 #include "anki/resource/Model.h"
+#include "anki/resource/DummyRsrc.h"
 #include "anki/resource/ProgramResource.h"
 #include "anki/resource/ParticleEmitterResource.h"
 #include "anki/resource/TextureResource.h"
@@ -23,8 +24,8 @@ ResourceManager::ResourceManager(Initializer& init)
 	m_tmpAlloc(StackMemoryPool(
 		init.m_allocCallback, init.m_allocCallbackData, 
 		init.m_tempAllocatorMemorySize)),
-	m_cacheDir(m_alloc),
-	m_dataDir(init.m_cacheDir, m_alloc)
+	m_cacheDir(init.m_cacheDir, m_alloc),
+	m_dataDir(m_alloc)
 {
 	// Init the data path
 	//
@@ -63,6 +64,7 @@ ResourceManager::ResourceManager(Initializer& init)
 	ANKI_RESOURCE(Skeleton)
 	ANKI_RESOURCE(ParticleEmitterResource)
 	ANKI_RESOURCE(Model)
+	ANKI_RESOURCE(DummyRsrc)
 
 #undef ANKI_RESOURCE
 }

+ 2 - 2
src/util/Memory.cpp

@@ -25,8 +25,8 @@ void* mallocAligned(PtrSize size, PtrSize alignmentBytes) noexcept
 #if ANKI_POSIX 
 #	if ANKI_OS != ANKI_OS_ANDROID
 	void* out;
-	int err = posix_memalign(
-		&out, getAlignedRoundUp(alignmentBytes, sizeof(void*)), size);
+	U alignment = getAlignedRoundUp(alignmentBytes, sizeof(void*));
+	int err = posix_memalign(&out, alignment, size);
 
 	if(!err)
 	{

+ 6 - 3
tests/framework/Framework.h

@@ -96,7 +96,8 @@ extern void deleteTesterSingleton();
 			std::stringstream ss; \
 			ss << "FAILURE: " << #x << " != " << #y << " (" \
 				<< file_ << ":" << line_ << ")"; \
-			throw std::runtime_error(ss.str()); \
+			fprintf(stderr, "%s\n", ss.str().c_str()); \
+			throw std::runtime_error("Test faled"); \
 		} \
 	} while(0);
 
@@ -107,7 +108,8 @@ extern void deleteTesterSingleton();
 			std::stringstream ss; \
 			ss << "FAILURE: " << #x << " == " << #y << " (" \
 				<< file_ << ":" << line_ << ")"; \
-			throw std::runtime_error(ss.str()); \
+			fprintf(stderr, "%s\n", ss.str().c_str()); \
+			throw std::runtime_error("Test faled"); \
 		} \
 	} while(0);
 
@@ -118,7 +120,8 @@ extern void deleteTesterSingleton();
 			std::stringstream ss; \
 			ss << "FAILURE: " << #x << " != " << #y << " (" \
 				<< file_ << ":" << line_ << ")"; \
-			throw std::runtime_error(ss.str()); \
+			fprintf(stderr, "%s\n", ss.str().c_str()); \
+			throw std::runtime_error("Test faled"); \
 		} \
 	} while(0);
 

+ 0 - 0
tests/gl/GlQueue.cpp


+ 35 - 1
tests/resource/ResourceManager.cpp

@@ -5,6 +5,7 @@
 
 #include "tests/framework/Framework.h"
 #include "anki/resource/ResourceManager.h"
+#include "anki/resource/DummyRsrc.h"
 #include "anki/core/Config.h"
 #include "anki/Gl.h"
 
@@ -29,7 +30,40 @@ ANKI_TEST(Resource, ResourceManager)
 	rinit.m_allocCallbackData = nullptr;
 	ResourceManager* resources = alloc.newInstance<ResourceManager>(rinit);
 
-	// Celete
+	// Load a resource
+	{
+		DummyResourcePointer a;
+
+		a.load("blah", resources);
+
+		{
+			DummyResourcePointer b = a;
+			a = b;
+			b = a;
+		}
+	}
+
+	// Load and load again
+	{
+		DummyResourcePointer a("blah", resources);
+		auto refcount = a.getReferenceCount();
+
+		DummyResourcePointer b("blah", resources);
+		ANKI_TEST_EXPECT_EQ(b.getReferenceCount(), a.getReferenceCount());
+		ANKI_TEST_EXPECT_EQ(a.getReferenceCount(), refcount + 1);
+
+		ANKI_TEST_EXPECT_EQ(b.get(), a.get());
+
+		// Again
+		DummyResourcePointer c("blah", resources);
+		ANKI_TEST_EXPECT_EQ(a.getReferenceCount(), refcount + 2);
+
+		// Load something else
+		DummyResourcePointer d("blih", resources);
+		ANKI_TEST_EXPECT_EQ(a.getReferenceCount(), refcount + 2);
+	}
+
+	// Delete
 	alloc.deleteInstance(resources);
 	alloc.deleteInstance(gl);
 }