For almost all of any object I've added so far (sf::Color, sf::Image, sf::Texture, etc.) to the sample code I grabbed from the SFML site, exceptions get thrown once I run it, to the accord of:
Unhandled exception at 0x61C71B86 (sfml-system-2.dll) in gameboiss.exe: 0xC0000005: Access violation reading location 0x00000074.
It's brought up in reference to the RenderWindow line for whatever reason. If I remove all lines referencing these objects, it works fines. Even if I leave only one line creating the variable (i.e. sf::Texture texture), the exception is still thrown. I've tried multiple things amongst looking at the locals/autos at debug and it doesn't seem to give much light.
I'm working on Visual Studio 2012, any help would be appreiciated. Below is the code. thanks :)
#include <iostream>
#include "SFML/Window.hpp"
#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
int main(){
sf::RenderWindow window(sf::VideoMode(200,200), "game boi");
sf::CircleShape shape(100.f);
//source of error
sf::Texture texture;
texture.loadFromFile("char\\spartapix.png");
/*if(!hero.loadFromFile("char\\spartapix.png")){
std::cerr << "Error: sprite not loaded.\n";
return 1;
}*/
//sf::Image background;
//if (!background.loadFromFile("background.jpg"))
//return -1;
shape.setFillColor(sf::Color::Blue);
sf::Vector2i pos;
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::GainedFocus)
std::cout << "playing";
if (event.type == sf::Event::LostFocus)
std::cout << "notplaying\n";
if (event.type == sf::Event::MouseButtonPressed){
sf::Vector2i pos = sf::Mouse::getPosition(window);
std::cout << pos.x << " " << pos.y << std::endl;
}
if (event.type == sf::Event::KeyPressed){
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
window.close();
}
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
<code>
I agree with RetiredNinja's comment above: If it happens as soon as you create the render window, it's most likely some STL version difference (from the passed string; since sf::String
is part of sfml-system), which is typically the case when you mix up versions (Visual Studio releases or Release/Debug builds).
Are you sure you've picked the correct download from SFML's download page? As an alternative, you could try downloading and compiling SFML from the official repository.
User contributions licensed under CC BY-SA 3.0