EDIT: It seems this works when I add to a 7z archive with no compression .. Which only changes filesize by 2MB anyway. Thanks for your time.
I'm not sure how.
I commented out what I did earlier (loadFromStream), updated with loadFromMemory, but got the same result:
sf::Texture* Sprites::load(const std::string& path) {
PhysFsStream gfxStream;
gfxStream.open(path.c_str());
void* data = malloc(1024*1024*4);
gfxStream.read(data, 1024*1024*4);
sf::Texture* img = new sf::Texture();
if(!img->loadFromMemory(data, 1024*1024*4)) {
delete img;
img = 0;
}
free(data);
/*
sf::Texture* img = new sf::Texture();
if(!img->loadFromStream(gfxStream)) {
delete img;
img = 0;
}*/
return img;
}
It probably works without compression because you did something wrong with compression ;)
You should really use smart pointers, see my article about RAII (http://www.bromeon.ch/articles/raii.html). It makes your code simpler and safer. There's no reason to manage memory manually in C++...
As you see, the following code is shorter and doesn't need to explicitly deallocate anything.
std::unique_ptr<sf::Texture> Sprites::load(const std::string& path) {
PhysFsStream gfxStream;
gfxStream.open(path.c_str()); // <- shouldn't this be checked for errors?
// allocate buffer
const std::size_t size = 1024*1024*4;
std::unique_ptr<char[]> data(new char[size]);
gfxStream.read(data.get(), size);
// allocate texture
auto img = std::make_unique<sf::Texture>();
if(!img->loadFromMemory(data.get(), size))
return nullptr;
return img;
}