c++ - SFML 仅适用于 Debug模式

标签 c++ window sfml

我正在尝试在 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/

相关文章:

c++ - 为什么我的日志在 std 命名空间中?

c++ - 在静态函数中调用成员函数指针

c# - WPF 应用程序在关闭主窗口时不会关闭

mysql - 本地计算机上的 MySQL 服务启动然后停止

c++ - 如何调用在另一个文件中找到的函数?

c++ - 如何区分 vector 中的字符? SFML 2.4.1

c++ - 从另一个模型中提取子模型?

java - 强制 java 应用程序成为焦点窗口

c++ - SFML 2.0 崩溃(window-d-2 错误

c++ - 如何正确使用 "__beginthreadex"?