SFML仅在调试模式下工作

SFML Only Works in Debug Mode

本文关键字:工作 模式 调试 SFML      更新时间:2023-10-16

我正试图在Visual Studio 2012中运行这个简单的SFML C++程序。它在调试模式下确实可以正常工作,但一旦我使用非调试库和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教程:

链接到与配置匹配的库非常重要:"sfml-xxx-d.lib"表示调试,"sfmlxxx.lib"代表发布。混合不好可能导致崩溃。

这里是红色的。