Using SFML 2.1 with MSVC 2012 on windows 7 64 bits. Can't really remember if I'm using the 64 bits version of the SFML lib.
struct menu
{
//map<string,Sprite> icons;
vector<Sprite> icons;
vector<Texture> tx;
vector<Text> texts;
Vec2 origin;
vector<string> filenames;
void init()
{
for(int i = 0; i < 50; ++i)
{
tx.push_back(Texture());
if(!tx.back().loadFromFile("png/beans.png")) cout << "could not open breeagfdso" << endl;
icons.push_back(Sprite(tx.back()));
}
cout << icons.size() << " elems" << endl;
float
c_x = icons.begin()->getTextureRect().width+2,
c_y = icons.begin()->getTextureRect().height+2;
cout << "cx cy = " << c_x << " " << c_y << endl;
int i = 0;
for(auto&a:icons)
{
a.setPosition(Vec2((i%4)*c_x, (i/4)*c_y)+origin);
++i;
}
}
void draw(RenderWindow&window)
{
for(auto&a:icons)
window.draw(a);
}
};
I think the code is pretty straightforward. I instantiate a menu and initialize it like this:
struct game
{
menu m;
void init()
{
m.origin=Vector2f(10,10);
m.init();
}
This is the error: Integer division by zero.
This previous code crashes if I set i < 3, the third displays fine, and 2 others are white squares. If I use only one texture and many sprites by just putting those 2 lines out of the loop like this:
tx.push_back(Texture());
if(!tx.back().loadFromFile("png/beans.png")) cout << "could not open breeagfdso" << endl;
for(int i = 0; i < 50; ++i)
{
icons.push_back(Sprite(tx.back()));
}
It runs fine and I see those icons displayed many times in rows.
I had a discussion lately on IRC about this, I was told I should use unique_ptr, but I don't think that's a solution since I use plain vectors, not vectors of pointers.
Can somebody tell me if it's a bug, or if the Texture class should not be used plain in a vector ?
Here is the call stack :
http://pastebin.com/47bJmH1cI remember outputing the size of the sprite rectangle like it was advised in one thread, I got some very large int number, but I don't understand why.