0xC0000005: Access violation reading location

-1

Hi i am new to using SFML library, i want to show an image using SFML library but getting "0xC0000005: Access violation reading location" error on following code: I have added the png file in the project location but still the code doesn't work

#include <SFML/Graphics.hpp>
#include<iostream>
int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::Texture t1;
    std::cout << "load enemy texture" << std::endl;
    //system("dir");

    if (!t1.loadFromFile("test.jpg")) {
        std::cout << "Could not load enemy texture" << std::endl;
        return 0;
    }
    
    sf::Sprite enemySprite;
    enemySprite.setTexture(t1);
    enemySprite.setPosition(sf::Vector2f(100, 100));

    while (window.isOpen())
    {
     
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(enemySprite);
        window.display();
    }

    return 0;
}
c++
visual-studio
runtime-error
sfml
asked on Stack Overflow Nov 23, 2020 by Viraj • edited Nov 23, 2020 by Viraj

1 Answer

0

as link suggested by @Yksisarvinen in the comment switching the configuration to Release suddenly made everything work.

To get the debug configuration to work, I just had to change the names from sfml-graphics.lib to sfml-graphics-d.lib (and so on).

Thank you guys.

answered on Stack Overflow Nov 23, 2020 by Viraj

User contributions licensed under CC BY-SA 3.0