Search code examples
c++access-violation

SFML loadFromFile() Access Violation Errors


So, I've been trying to use SFML's loadFromFile() funtion and it keeps giving me an access violation error. It keeps going back and forth between giving me errors and not giving any. Every time I think it's working, it begins giving errors again.

#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>


int main()
{

    sf::RenderWindow window(sf::VideoMode(1000, 1000), "SFML works!");

    sf::Image newImage;
    sf::Texture newTexture;
    newImage.loadFromFile("bg_grid.jpg"); //access violation error occurs right here


    newTexture.loadFromImage(newImage);
    sf::Sprite newSprite(newTexture);


    return 0;
}

The debug folders I'm including are "sfml-system-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;" I've tried adding the exact file address and it still doesn't work. What are some possible causes for the random access violation errors?


Solution

  • Okay, guys, I figured out the problem and I'm leaving this here for anyone in the future who has the same problem. Basically, before, my additional dependencies were "sfml-system.lib;sfml-system-d.lib;sfml-graphics.lib;sfml-graphics-d.lib;sfml-window.lib;sfml-window-d.lib;%(AdditionalDependencies)". I removed the non debug libraries (the ones without "-d") and it became just "sfml-system-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;%(AdditionalDependencies)". It works well now.