The error is quite possibly caused by the fact that this line
m_Texture = sf::Texture(AssetManager::LoadTexture(path));
is copying the texture at least once. You should be storing references to your textures in the sprite, not copies.
To start with ensure that your asset manager returns a reference to the held textures, else you'll be getting a copy here (you haven't shared the code for your asset manager). It should look something like
sf::Texture& AssetManager::loadTexture(const std::string& path)
Then use a reference (or a pointer) to sf::Texture in your sprite class and use an
initialiser list to set it up correctly on construction.
As a side note: placing your asset manager as a sprite member is somewhat redundant, you'll be creating a new asset manager with every sprite. The idea of asset managers is that a single instance exists which can share its held resources with multiple sprites (or other types eg sounds etc). I'd suggest refactoring your sprite class to something like:
class Sprite {
public:
sf::Texture& m_Texture;
sf::Sprite m_Sprite;
sf::Vector2f sprite_scale;
sf::Vector2u original_size;
sf::Vector2f texture_size;
Sprite(sf::Texture&,sf::IntRect rect,sf::Vector2f size);
};
Sprite::Sprite(sf::Texture& texture, sf::IntRect rect, sf::Vector2f size)
: m_texture(texture),
m_sprite(texture)
{
m_Sprite.setTextureRect(rect);
original_size = m_Texture.getSize();
texture_size.x = static_cast<float>(original_size.x);
texture_size.y = static_cast<float>(original_size.y);
sprite_scale.x = size.x / texture_size.x;
sprite_scale.y = size.y / texture_size.y;
m_Sprite.setScale(sf::Vector2f(sprite_scale.x, sprite_scale.y));
m_Sprite.setOrigin(sf::Vector2f(original_size.x / 2, original_size.y / 2));
}
Note that the texture is passed purely by reference, removing any copy operations (which should hopefully fix your OpenGL error). The sprite and texture members are both initialised with an initialiser list (which you should be using in all of your constructors, btw).To use this sprite class make sure to add a single instance of your asset manager to your game class (or wherever your sprites are created) then pass texture references from it like so:
Sprite spr1(m_assetManager.loadTexture(path), rect, size);
Sprite spr2(m_assetManager.loadTexture(otherPath), otherRect, otherSize);
This way your asset manager *owns* a single instance of each texture, references to which are passed out and shared with as many sprites which need them.
Although when all is said an done you can remove the sf::Texture member entirely: the sf::Sprite member will hold a reference for you and all your texture queries can be done through sf::Sprite::getTexture()