I am new to c ++ / SFML and I don't know why my program cannot load a texture, I tried putting the image in my project folder and in the debug folder but it didn't work.
Code:
int main() {
sf::RenderWindow window(VideoMode(600,600),"Window");
sf::Event event;
sf::Texture textura;
textura.loadFromFile("icono.png");
sf::Sprite sprite1(textura);
while (window.isOpen()) {
while (window.pollEvent(event)) {
if (event.type== sf::Event::EventType::Closed) {
window.close();
}
}
window.clear();
window.draw(sprite1);
window.display();
}
}
The error is "Unhandled exception at 0x5F6D3647 (vcruntime140.dll) in TestSFML.exe: 0xC0000005: Access violation while reading location 0x00701000" in the line "textura.loadFromFile("icono.png");"
I found the answer and share it in case it helps. The possible solution is to add the SFML debug libraries in "additional dependencies", the libraries are "sfml-graphics-d.lib" and "sfml-system-d.lib".
User contributions licensed under CC BY-SA 3.0