1
Graphics / Access violation writing location
« on: August 10, 2018, 12:19:34 pm »
Recently I've started working with SFML 2.5. I have the following function that loads a sprite by path and the main method to test it:
Everything works fine if I write this code inside the main method. The exception is thrown only when writing a separate function that loads and returns a texture.
Here is the call stack:
My IDE is Visual Studio 2017.
P.S. Sorry if there were some mistakes in the topic. I do not know English well enough.
#include <SFML/Graphics.hpp>
#include <string>
#include <exception>
sf::Texture loadTexture(const std::string& path)
{
sf::Texture texture;
if (!texture.loadFromFile(path))
{
throw std::runtime_error("Could not open file: " + path);
}
return texture; // This line causes an exception to throw
}
int main()
{
sf::Texture gameFieldTexture = loadTexture("graphics/field.png");
return 0;
}
Every time I run the application the commented line above causes an exception to throw with the message:"Unhandled exception at 0x1002DB43 (ig4icd32.dll) in App2_TicTacToe.exe: 0xC0000005: Access violation writing location at 0x00000010".#include <string>
#include <exception>
sf::Texture loadTexture(const std::string& path)
{
sf::Texture texture;
if (!texture.loadFromFile(path))
{
throw std::runtime_error("Could not open file: " + path);
}
return texture; // This line causes an exception to throw
}
int main()
{
sf::Texture gameFieldTexture = loadTexture("graphics/field.png");
return 0;
}
Everything works fine if I write this code inside the main method. The exception is thrown only when writing a separate function that loads and returns a texture.
Here is the call stack:
(click to show/hide)
My IDE is Visual Studio 2017.
P.S. Sorry if there were some mistakes in the topic. I do not know English well enough.