Quick backstory:I'm collecting useful classes inside my own library called Vildhjarta that is dependent on SFML, it's dynamic ( .dll ) and links statically towards SFML when compiled.
ProblemInside Vildhjarta there is a class called "Graphics" that loads and returns texture files and caches them inside a map.
Problem is when using Graphics::getTexture() ( loads texture if not found in cache ) it returns a valid pointer but It doesn't display when trying to draw it.
I can however access it, getting information such as size.
Minimal RecreationTricky but here is the main.cpp:
#include <SFML\Graphics.hpp>
#include <Vildhjarta\Graphics.hpp>
#include <iostream>
int main(int argc, char **argv)
{
sf::RenderWindow window(sf::VideoMode(600,400,32), "@Window" );
sf::Event event;
vh::Graphics g;
sf::Texture* t = new sf::Texture();
std::cout << t->getSize().x << " " << t->getSize().y << std::endl;
delete t;
t = g.getTexture("victorsplash.png");
std::cout << t->getSize().x << " " << t->getSize().y << std::endl;
sf::Sprite s;
s.setTexture((*t));
while( window.isOpen() )
{
while( window.pollEvent(event))
{
}
window.clear(sf::Color::Black);
window.draw(s);
window.display();
}
return 0;
}
Here is Graphic.hpp inside Vildhjarta.dll :
#ifndef _WELLSPRING_GRAPHICS_HPP
#define _WELLSPRING_GRAPHICS_HPP
#include <SFML\Graphics.hpp>
//#include "ResourceCache.hpp"
#include <string>
#include <map>
namespace vh
{
class Graphics
{
public:
sf::Texture* getTexture(std::string gfx);
void removeTexture(std::string gfx);
void loadTexture(std::string gfx);
private:
//vh::ResourceCache<sf::Texture> m_cache;
std::map<std::string, sf::Texture*> m_cache;
};
}
#endif
And here is the implementation ( stripped from everything else ):
/* Includers and stuff */
sf::Texture* vh::Graphics::getTexture(std::string gfx)
{
sf::Texture* texture = nullptr;
if( m_cache.find(gfx) != m_cache.end())
texture = m_cache[gfx];
if( texture == nullptr )
{
texture = new sf::Texture();
if( !texture->loadFromFile(gfx) )
{
std::cout << "Graphics couldnt load file " << gfx << std::endl;
delete texture;
return nullptr;
}
std::cout << "Graphics loaded file " << gfx << " correctly" << std::endl;
m_cache[gfx] = texture;
}
std::cout << "Returned texutre pointer" << std::endl;
return m_cache[gfx];
}
Additional informationThe above code will output 0,0 and then after calling graphics-getTexture("victorsplash.png") it will output 600,400 which is the dimension of the image that is loaded, but setting the sprite to it will still not draw it.
If I include the raw files i.e the headers and .cpp files to my project it works fine, loading and drawing.
Both the project and the library project links statically towards SFML
I have no clue on how to solve this, I'v been trying like crazy.