Beispiel #1
0
//=================================================================================================
void DAllocTracer::reportLeaks()
{
	if(m_NbAllocs <= 1)
		DPrint("%i allocation performed.", m_NbAllocs);
	else
		DPrint("%i allocations performed.", m_NbAllocs);

	if(m_AllocMap.size())
	{
		u32 size = 0;
		
		for(std::map<void*, DS_Allocation>::iterator it = m_AllocMap.begin(); it != m_AllocMap.end(); it++)
		{
			DWarning("%s(%i): Memory leak of %i bytes found.", it->second.pFile, it->second.line, it->second.size);

			size += it->second.size;
			free(it->first);
		}
		
		if(m_AllocMap.size() == 1)
			DWarning("%i block of memory has not been freed (%i bytes).", m_AllocMap.size(), size);
		else
			DWarning("%i blocks of memory have not been freed (%i bytes).", m_AllocMap.size(), size);
	}
	else
		DPrint("No memory leak found.");
}
//=================================================================================================
void DResourceManager::unloadModel(const char* pFileName)
{
	std::map<DString, DS_ModelDataResource>::iterator it = m_ModelDataMap.find(pFileName);
	if(it != m_ModelDataMap.end())
	{
		if(!(--(it->second.refCount)))
		{
			delete it->second.pModelData;
			m_ModelDataMap.erase(it);
		}
	}
	else
		DWarning("Attempting to unload unknown model \"%s\".", pFileName);
}
//=================================================================================================
void DResourceManager::unloadTexture(const char* pFileName)
{
	std::map<DString, DS_TextureResource>::iterator it = m_TextureMap.find(pFileName);
	if(it != m_TextureMap.end())
	{
		if(!(--(it->second.refCount)))
		{
			delete it->second.pTexture;
			m_TextureMap.erase(it);
		}
	}
	else
		DWarning("Attempting to unload unknown texture \"%s\".", pFileName);
}
//=================================================================================================
DResourceManager::~DResourceManager()
{
	// Destruction des meshs
	for(std::map<DString, DS_ModelDataResource>::iterator it = m_ModelDataMap.begin(); it != m_ModelDataMap.end(); it++)
	{
		DWarning("Model \"%s\" has not been unloaded.", it->first.getCStr());
		delete it->second.pModelData;
	}

	// Destruction des shaders
	for(std::map<DString, DS_ShaderResource>::iterator it = m_ShaderMap.begin(); it != m_ShaderMap.end(); it++)
	{
		DWarning("Shader \"%s\" has not been unloaded.", it->first.getCStr());
		delete it->second.pShader;
	}

	// Destruction des textures
	for(std::map<DString, DS_TextureResource>::iterator it = m_TextureMap.begin(); it != m_TextureMap.end(); it++)
	{
		DWarning("Texture \"%s\" has not been unloaded.", it->first.getCStr());
		delete it->second.pTexture;
	}
}
Beispiel #5
0
static int luasrc_DWarning (lua_State *L) {
  DWarning(luaL_checkstring(L, 1), luaL_checkint(L, 2), luaL_checkstring(L, 3));
  return 0;
}