So, I've made a class for player object and something strange is going on.
Constructor:
Object::Object(sf::String path) {
image = new sf::Image;
image->loadFromFile(path);
tex = new sf::Texture;
tex->loadFromImage(*image);
spriteWidth=tex->getSize().y;
spriteHeight=tex->getSize().y;
sprite = new sf::Sprite;
sprite->setTexture(*tex);
Init();
SetOrigin(xo,yo);
SetBBox(0,0,spriteWidth,spriteHeight);
Object::SetFrame(animFrame);
renderStates.blendMode=sf::BlendNone;
delete image;
};
Destructor:
Object::~Object() {
delete sprite;
delete tex;
};
Piece of Main.cpp
window.clear();
window.draw(BG);
window.draw(rect);
window.draw(*Player.sprite);
window.draw(sprite);
window.draw(text);
window.display();
Now the problem is when I run it as it is it gives me "Acces violation" error. Can't find a sprite, I guess, 'cause it crashes on window.draw(*Player.sprite). But if I comment the whole destructor, it runs just fine. Is there anything I am missing?
Also, how does resource freeing works in SFML? I mean, resources should be removed somehow to not take memory away, right?