1

I am trying to run this simple SFML C++ program in Visual Studio 2012. It does work fine in debug mode, but as soon as I use the non-debug libraries and DLLs the program throws an Access Violation exception on the first line of code. If I remove the assignment (and the dependencies of the assignment), and just run 'sf::VideoMode::getFullscreenModes();' it works fine.

I have the libraries dynamically linked.

#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;
}
4

1 回答 1

3

简短回答:您不能混合调试/发布二进制文件。

引用 Visual Studio 的官方 SFML 教程:

链接到与配置匹配的库很重要:“sfml-xxx-d.lib”用于调试,“sfml-xxx.lib”用于发布。糟糕的组合可能会导致崩溃。

这里是红色的。

于 2013-07-21T22:29:24.193 回答