【发布时间】:2017-05-15 04:41:54
【问题描述】:
到目前为止,对于我从 SFML 站点获取的示例代码中添加的几乎所有对象(sf::Color、sf::Image、sf::Texture 等),一旦我添加了异常就会抛出运行它,符合:
gameboiss.exe 中 0x61C71B86 (sfml-system-2.dll) 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000074。
无论出于何种原因,它都是在参考 RenderWindow 行时提出的。如果我删除所有引用这些对象的行,它就可以正常工作。即使我只留下一行来创建变量(即 sf::Texture 纹理),仍然会抛出异常。在调试时查看本地人/汽车时,我尝试了多种方法,但它似乎没有给出太多的光。
我正在开发 Visual Studio 2012,如有任何帮助,我们将不胜感激。下面是代码。谢谢:)
#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>
【问题讨论】:
-
您确定您的 sfml 版本与您的编译器完全匹配吗?当版本不匹配时,我看到了类似的问题。
标签: c++ visual-studio visual-studio-2012 sfml