<commit_before>#include "AssetLoader.h"
#include <iostream>

namespace fse
{
	AssetLoader::AssetLoader() {

	}

	AssetLoader::~AssetLoader()
	{
	}

	sf::Texture& AssetLoader::getSFTexture(std::string path)
	{
		if (textureMap.count(path)) //Texture is already loaded
		{
			textureCounter[path]++;
		}
		else
		{
			loadTexture(path);
		}
		return textureMap[path];
	}

	AssetLoader::Texture AssetLoader::getTexture(std::string path)
	{
		return Texture(this, path, &getSFTexture(path));
	}

	void AssetLoader::releaseSFTexture(std::string path)
	{
		if (textureCounter.size() == 0)
			return;
		if (!textureCounter.count(path)) //Texture is not in memory
			return;
		if (textureCounter[path] == 1)
		{
			textureCounter.erase(path);
			textureMap.erase(path);

			std::cout << "erasing texture: " << path << "\n";

			return;
		}

		textureCounter[path]--;
	}

	void AssetLoader::loadTexture(std::string path)
	{
		std::string realPath = "data/" + path;
		textureMap[path].loadFromFile(realPath.c_str());
		textureCounter[path] = 1;
	}


	AssetLoader::Texture::Texture() : loader_(nullptr), tex_(nullptr)
	{
	}

	AssetLoader::Texture::Texture(const Texture& texture) : loader_(texture.loader_), path_(texture.path_), tex_(texture.tex_)
	{
		loader_->textureCounter[path_]++;
	}

	AssetLoader::Texture::Texture(AssetLoader* loader, std::string path, sf::Texture* tex) : loader_(loader), path_(path), tex_(tex)
	{
	}

	AssetLoader::Texture::~Texture()
	{
		if (path_ != "")
			loader_->releaseSFTexture(path_);
	}

	sf::Texture& AssetLoader::Texture::get() const
	{
		return *tex_;
	}

	AssetLoader::Texture& AssetLoader::Texture::operator=(const Texture& texture)
	{
		if (&texture == this)
			return *this;

		Texture tmp(texture);
		std::swap(loader_, tmp.loader_);
		std::swap(path_, tmp.path_);
		std::swap(tex_, tmp.tex_);

		loader_->textureCounter[path_]++;

		return *this;
	}

	sf::Texture* AssetLoader::Texture::operator->() const
	{
		return tex_;
	}
}<commit_msg>AssetLoader: Fix wrapped textures leaking<commit_after>#include "AssetLoader.h"
#include <iostream>

namespace fse
{
	AssetLoader::AssetLoader() {

	}

	AssetLoader::~AssetLoader()
	{
	}

	sf::Texture& AssetLoader::getSFTexture(std::string path)
	{
		if (textureMap.count(path)) //Texture is already loaded
		{
			textureCounter[path]++;
		}
		else
		{
			loadTexture(path);
		}
		return textureMap[path];
	}

	AssetLoader::Texture AssetLoader::getTexture(std::string path)
	{
		return Texture(this, path, &getSFTexture(path));
	}

	void AssetLoader::releaseSFTexture(std::string path)
	{
		if (textureCounter.size() == 0)
			return;
		if (!textureCounter.count(path)) //Texture is not in memory
			return;
		if (textureCounter[path] == 1)
		{
			textureCounter.erase(path);
			textureMap.erase(path);

			std::cout << "erasing texture: " << path << "\n";

			return;
		}

		textureCounter[path]--;
	}

	void AssetLoader::loadTexture(std::string path)
	{
		std::string realPath = "data/" + path;
		textureMap[path].loadFromFile(realPath.c_str());
		textureCounter[path] = 1;
	}


	AssetLoader::Texture::Texture() : loader_(nullptr), tex_(nullptr)
	{
	}

	AssetLoader::Texture::Texture(const Texture& texture) : loader_(texture.loader_), path_(texture.path_), tex_(texture.tex_)
	{
		loader_->textureCounter[path_]++;
	}

	AssetLoader::Texture::Texture(AssetLoader* loader, std::string path, sf::Texture* tex) : loader_(loader), path_(path), tex_(tex)
	{
	}

	AssetLoader::Texture::~Texture()
	{
		if (path_ != "")
			loader_->releaseSFTexture(path_);
	}

	sf::Texture& AssetLoader::Texture::get() const
	{
		return *tex_;
	}

	AssetLoader::Texture& AssetLoader::Texture::operator=(const Texture& texture)
	{
		if (&texture == this)
			return *this;

		Texture tmp(texture);
		std::swap(loader_, tmp.loader_);
		std::swap(path_, tmp.path_);
		std::swap(tex_, tmp.tex_);

		return *this;
	}

	sf::Texture* AssetLoader::Texture::operator->() const
	{
		return tex_;
	}
}
{'fraction_non_alphanumeric': 0.16789246766421506, 'fraction_numerical': 0.001521683996956632, 'mean_word_length': 4.834319526627219, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7205231', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1342, 'n_words': 241}