我正在尝试在 Visual Studio 2012 中运行这个简单的 SFML C++ 程序。它在 Debug模式下运行良好,但只要我使用非调试库和 DLL,程序就会在第一行抛出访问冲突异常的代码。如果我删除分配(以及分配的依赖项),然后运行“sf::VideoMode::getFullscreenModes();”它工作正常。
我有动态链接的库。
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>
int main(int argCount, char** argVector) {
std::vector<sf::VideoMode> vm = sf::VideoMode::getFullscreenModes(); // Access Violation in Non-Debug Mode
sf::VideoMode videoMode;
for(unsigned i = 0; i < vm.size(); i++) {
if(vm[i].isValid()) {
videoMode = vm[i];
break;
}
std::cout << "Invalid VideoMode: " << i << std::endl;
}
sf::Window window(videoMode, "SFML OpenGL", sf::Style::Fullscreen);
glClearDepth(0.5F);
glOrtho(0, 1, 0, 1, 0, 1);
std::cout << glGetError();
glColor3f(0, 1, 0);
{
glBegin(GL_QUADS);
glVertex3i(0, 0, 0);
glVertex3i(0, 1, 0);
glVertex3i(1, 1, 0);
glVertex3i(1, 0, 0);
glEnd();
}
window.display();
while(window.isOpen()) {}
return 0;
}
最佳答案
简短回答:您不能混合调试/发布二进制文件。
引用 Visual Studio 的官方 SFML 教程:
It is important to link to the libraries that match the configuration: "sfml-xxx-d.lib" for Debug, and "sfml-xxx.lib" for Release. A bad mix may result in crashes.
它是红色的here .
关于c++ - SFML 仅适用于 Debug模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17771979/