SFML Program Access violation reading location

0

I am currently working on a 2D SFML game and I am getting an access violation that i can't seem to wrap my head around. I am getting the error while creating my SpriteManager class.

sf::Sprite *SpriteManager::getSprite(const std::string &name){
auto it = Sprites.find(name); 
if (it == Sprites.end())
{
    sf::Sprite *sp = NULL;
    sf::Texture tex;

    if (tex.loadFromFile(name)) 
    {                           //Access violation reading location
        sp->setTexture(tex);    //Get Access Violation here
        setSprite(name, sp);
    }
    else {
        return NULL;
    }

    delete tex;
    return sp;
}

return it->second;

The objective here is to call getSprite("filename") and it should check if it is already in my unordered array of Sprites, if not it should create/load the texture, assign it to the sprite, add the sprite to the array and return it.

The exact exception thrown is:

Exception thrown at 0x0F314626 (sfml-graphics-d-2.dll) in Game.exe: 0xC0000005: Access violation reading location 0x000000FC.

I am referencing this youtube tutorial and converting it to SFML. https://youtu.be/9pQ99zLKDx0?t=10m20s

I also get all kinds of other errors concerning this sf::Texture tex. If I remove the sp->setTexture(tex); line i get an access writing violation at tex.loadFromFile(name).
I am still fairly new to programming and I do not have much experience troubleshooting access violations. I appreciate the help.

c++
sfml
asked on Stack Overflow Sep 16, 2018 by Bro_Mayo_ • edited Sep 18, 2018 by Alex Meuer

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0