使用SFML RenderWindow时,内存位置的std::length_error
std::length_error at memory location When using SFML RenderWindow
我的项目使用SFML,目前正在学习网站上的教程。
目前,我只完成了使用以下代码(直接从教程中粘贴)创建RenderWindow的第一步:
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
int main()
{
// create the window
sf::VideoMode vm (800, 600);
sf::RenderWindow window(vm, "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::Black);
// draw everything here...
// window.draw(...);
// end the current frame
window.display();
}
return 0;
}
它编译得很好,但当我运行它时,我会得到以下异常:
First-chance exception at 0x76BFC42D in OpenGlTest.exe: Microsoft C++
exception: std::length_error at memory location 0x0046F754.
我尝试调试并将std::length_error跟踪到RenderWindow构造函数:
sf::RenderWindow window(vm, "My window");
我对c++和OpenGL非常缺乏经验,所以我不知道如何继续,它不会让我进入构造函数查看发生了什么,它只是立即抛出异常。
感谢您的帮助。
我想我发现了问题。我不确定这是修复还是运气好,但如果在使用Visual C++时链接到sfml-xxxx.lib而不是sfml-xxxx-d.lib,显然会发生崩溃。在那次改变之后,它似乎确实起了作用。
我不是SFML的专家,但当你创建这样的窗口时,会有窗口按钮,它们总共需要10多个像素。
你试过加大码吗?试试200,就像教程中所做的那样。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- 如何获取std::result_of函数的返回类型
- std::string.length() not counting
- 为什么 std::regex_match 不支持 "zero-length assertions" ?
- C++ std::string length() 或 size() 不适用于方法参数
- std::string的size()和length()有什么不同吗
- C 字符串的长度:std::strlen() vs. std::<char>char_traits::length()
- 将std::string::length转换为int
- 0-length数组(或std::array)有什么用
- std::string::length() vs. std::string::size()