2016-12-30 120 views
0

對於我迄今爲止添加的任何對象(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>
+1

您確定您的sfml版本與您的編譯器完全匹配嗎?當版本不匹配時,我看到類似的問題。 –

回答

0

我同意上述RetiredNinja的評論:如果一旦你創建渲染窗口發生了,這是最有可能的一些STL版本的差異(從傳遞的字符串;因爲sf::StringSFML的一部分 - 系統),當您混淆版本(Visual Studio版本或Release/Debug版本)時通常會出現這種情況。

您確定您已選擇correct download from SFML's download page?作爲替代,您可以嘗試從official repository下載和編譯SFML。