對於我迄今爲止添加的任何對象(sf :: Color,sf :: Image,sf :: Texture等)到我從SFML中抓取的示例代碼現場,異常拋出,一旦我運行它,來的協議:SFML - RenderWindow運行時錯誤與一切
未處理的異常在0x61C71B86(SFML系統-2.DLL)在gameboiss.exe:0000005:訪問衝突讀取位置0x00000074。
無論出於何種原因,它都引用了RenderWindow行。如果我刪除所有引用這些對象的行,它將工作得很好。即使我只留下一行創建變量(即sf :: Texture 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版本與您的編譯器完全匹配嗎?當版本不匹配時,我看到類似的問題。 –