【问题标题】:SFML - RenderWindow Runtime Errors with EVERYTHINGSFML - 一切都出现 RenderWindow 运行时错误
【发布时间】: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


【解决方案1】:

我同意 RetiredNinja 上面的评论:如果它在您创建渲染窗口后立即发生,则很可能是 STL 版本差异(来自传递的字符串;因为sf::Stringsfml-system 的一部分 em>),这通常是您混合版本(Visual Studio 版本或发布/调试版本)时的情况。

您确定您选择了correct download from SFML's download page?作为替代方案,您可以尝试从 official repository 下载和编译 SFML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-23
    • 2014-02-13
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多