Hi. I am developing a game with SFML, and I'm running into a memory issue that I don't understand. If I load too much memory in textures, I get a message "Failed to load image. Reason: Out of memory" from SFML. The reason that this is confusing is I feel like I'm using significantly less memory than should cause this issue. I have a modern computer with a solid graphics card (NVIDIA GeForce GTX 1060 6GB). I have written a small program to demonstrate my issue. Using the formula 2048x2048x4x(number of textures) to figure out roughly how much memory I've used, it crashes at around 1700 MB, or 100 textures of size 2048x2048. Not sure if the number is right. Does anyone know what I'm doing wrong or what this issue is?
#include <iostream>
#include <SFML\Graphics.hpp>
#include "Tileset.h"
#include <SFML/OpenGL.hpp>
using namespace std;
using namespace sf;
const static int NUM_TEX = 1000;
int main()
{
Texture *texs[NUM_TEX];
string thing = "goal_w1_b_512x512.png";
int x;
for (int i = 0; i < NUM_TEX; ++i)
{
Texture *tex = new Texture();
if (!tex->loadFromFile(thing))
{
delete tex;
cout << "failed to load: " << thing << "\n";
cin >> x;
return 0;
}
int num = tex->getSize().x * tex->getSize().y * 4 * i;
double memD = num;
double megs = memD / 1000000.0;
cout << "megs: " << megs << endl;
texs[i] = tex;
cout << i << "\n";
}
for (int i = 0; i < NUM_TEX; ++i)
{
delete texs[i];
}
cout << "done" << endl;
cin >> x;
return 0;
}