#include <SFML/Graphics.hpp>
#include <string>
#include <vector>
using namespace std;using namespace sf;
class Obj
{
public:
Obj(int x, int y, string path) : _x(x), _y(y), _path(path)
{
texture.loadFromFile(path);
sprite.setTexture(texture);
}
void create()
{
texture.loadFromFile(path);
sprite.setTexture(texture);
}
int _x;
int _y;
string path;
Sprite sprite;
Texture texture;
};
int main()
{
//Вот так рисуется:
std::vector<Obj> obj;
obj.emplace_back(16, 16, "res/sprite.png");
//Но если 2строки выше заменить этим:
std::vector<Obj> obj;
Obj.reserve(1);
Obj[0].x = 16;
Obj[0].y = 16;
Obj[0].path = "res/sprite.png";
Obj[0].create();
window()
{
while (window.isOpen())
{
window.draw(Obj[0].sprite); //эта строка начнет крашить приложение
}
}
return 0;
}
I2luY2x1ZGUgPFNGTUwvR3JhcGhpY3MuaHBwPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkO3VzaW5nIG5hbWVzcGFjZSBzZjsKCmNsYXNzIE9iagp7CnB1YmxpYzoKCU9iaihpbnQgeCwgaW50IHksIHN0cmluZyBwYXRoKSA6IF94KHgpLCBfeSh5KSwgX3BhdGgocGF0aCkKCXsKCQl0ZXh0dXJlLmxvYWRGcm9tRmlsZShwYXRoKTsKCQlzcHJpdGUuc2V0VGV4dHVyZSh0ZXh0dXJlKTsKCX0KCXZvaWQgY3JlYXRlKCkKCXsKCQl0ZXh0dXJlLmxvYWRGcm9tRmlsZShwYXRoKTsKCQlzcHJpdGUuc2V0VGV4dHVyZSh0ZXh0dXJlKTsKCX0KCQoJaW50IF94OwoJaW50IF95OwoJc3RyaW5nIHBhdGg7CglTcHJpdGUgc3ByaXRlOwoJVGV4dHVyZSB0ZXh0dXJlOwp9OwoKaW50IG1haW4oKSAKewoJLy/QktC+0YIg0YLQsNC6INGA0LjRgdGD0LXRgtGB0Y86CglzdGQ6OnZlY3RvcjxPYmo+IG9iajsKCW9iai5lbXBsYWNlX2JhY2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