glfwSwapBuffers выбрасывает _com_error - PullRequest
1 голос
/ 07 февраля 2020

Я использую glfw 3.3.2 с примером программы в документации:

#define GLEW_STATIC
#include <GLEW/glew.h>
#include <GLFW/glfw3.h>
#include <iostream>

/* uncomment to attempt to draw a triangle
static unsigned int compile_shader(unsigned int type, const std::string& source) {

    unsigned int id = glCreateShader(type);
    const char* src = source.c_str();
    glShaderSource(id, 1, &src, nullptr);
    glCompileShader(id);

    // error handling
    int res;
    glGetShaderiv(id, GL_COMPILE_STATUS, &res);
    if (res == GL_FALSE) {
        // shader did not compile sucessfully
        int len;
        glGetShaderiv(id, GL_INFO_LOG_LENGTH, &len);
        char* msg = (char*) _malloca(len * sizeof(char));
        glGetShaderInfoLog(id, len, &len, msg);
        std::cout << "Failed to compile " << 
            (type == GL_VERTEX_SHADER ? "vertex" : "fragment")
            << " shader" << std::endl;
        std::cout << msg << std::endl;
        glDeleteShader(id);
        return 0;
    }

    return id;
}

static int create_shader(const std::string& vertex_shader, const std::string& fragment_shader) {

    GLuint program = glCreateProgram();
    GLuint vs = compile_shader(GL_VERTEX_SHADER, vertex_shader);
    GLuint fs = compile_shader(GL_FRAGMENT_SHADER, fragment_shader);

    glAttachShader(program, vs);
    glAttachShader(program, fs);
    glLinkProgram(program);
    glValidateProgram(program);

    glDeleteShader(vs);
    glDeleteShader(fs);

    return program;
}
*/

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();

        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

/* uncomment to attempt to draw a triangle
 if (glewInit() != GLEW_OK) {
        std::cout << "glew init error" << std::endl;
        return -1;
    }

    std::cout << glGetString(GL_VERSION) << std::endl;

    // define vertex buffer
    float positions[6] = {
        -0.5f, -0.5f,
         0.0f,  0.5f,
         0.5f, -0.5f
    };
    unsigned int buffer;
    glGenBuffers(1, &buffer);
    glBindBuffer(GL_ARRAY_BUFFER, buffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, positions, GL_STATIC_DRAW);

    // enable the 0th (first) vertex attribute array
    glEnableVertexAttribArray(0);
    // 0 means first attribute, 2 means how many vertex to represent the attribute (x and y)
    // sizeof(float) * 2 is the bytes needed to skip to get to the next attribute
    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);

    // core means no depracated function
    // 330 is the version
    // location = 0 should match the first arg of gl vertex attribute pointer call
    std::string vertex_shader =
        "#version 330 core\n"
        "\n"
        "layout(location = 0) in vec4 position;"
        "\n"
        "void main()\n"
        "{\n"
        "gl_Position = position;\n"
        "}\n";

    std::string fragment_shader =
        "#version 330 core\n"
        "\n"
        "layout(location = 0) out vec4 color;"
        "\n"
        "void main()\n"
        "{\n"
        "  color = vec4(1.0, 0.0, 0.0, 1.0);\n"
        "}\n";

    unsigned int shader = create_shader(vertex_shader, fragment_shader);
    glUseProgram(shader);
*/

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {

        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

// uncomment the following to attempt to draw a triangle
//  glDeleteProgram(shader);

    glfwTerminate();
    return 0;
}

У меня получилось странное Microsoft C++ exception: _com_error:

'opengl_project.exe' (Win32): Loaded 'D:\University_of_Manchester\Projects\OpenGL\opengl_project\x64\Debug\opengl_project.exe'. Symbols loaded.
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\windows.storage.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\profapi.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\umpdc.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\cryptsp.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\opengl32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\glu32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DXCore.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. 
The thread 0x4b10 has exited with code 0 (0x0).
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\winmmbase.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\winmmbase.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\dinput8.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\XInput1_4.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\devobj.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\InputHost.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\propsys.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\CoreUIComponents.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\CoreMessaging.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ntmarta.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\WinTypes.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\WinTypes.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\hid.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\setupapi.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\wintrust.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\msasn1.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\crypt32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvdlistx.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\version.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvdlistx.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvoglv64.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\wtsapi32.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\version.dll'. 
The thread 0x4bc0 has exited with code 0 (0x0).
The thread 0x4bc8 has exited with code 0 (0x0).
The thread 0x4bc4 has exited with code 0 (0x0).
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\nvspcap64.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\winsta.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\dxgi.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\d3d11.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ResourcePolicyClient.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\ResourcePolicyClient.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvdlistx.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvdlistx.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvldumdx.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\cryptnet.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\imagehlp.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\rsaenh.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\nvwgf2umx.dll'. 
The thread 0x25fc has exited with code 0 (0x0).
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\NvCamera\NvCameraWhitelisting64.dll'. 
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nvaci.inf_amd64_bf1cc4a1e8a34392\NvCamera\NvCameraWhitelisting64.dll'
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\TextInputFramework.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\iertutil.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_1d9a63fa126c4a34\igd10iumd64.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ncrypt.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\ntasn1.dll'. 
'opengl_project.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_1d9a63fa126c4a34\igc64.dll'. 
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
[...] more same exceptions here
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
Exception thrown at 0x00007FFBFE2AA839 in opengl_project.exe: Microsoft C++ exception: _com_error at memory location 0x00000023B52FBAE0.
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_1d9a63fa126c4a34\igc64.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\ntasn1.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\ncrypt.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\igdlh64.inf_amd64_1d9a63fa126c4a34\igd10iumd64.dll'
The thread 0x295c has exited with code 0 (0x0).
The thread 0x2960 has exited with code 0 (0x0).
The thread 0x2ae4 has exited with code 0 (0x0).
The thread 0x48a8 has exited with code 0 (0x0).
The thread 0x3f98 has exited with code 0 (0x0).
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\XInput1_4.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\hid.dll'
'opengl_project.exe' (Win32): Unloaded 'C:\Windows\System32\dinput8.dll'
The thread 0x4bb0 has exited with code 0 (0x0).
The thread 0x4bcc has exited with code 0 (0x0).
The thread 0x4bb4 has exited with code 0 (0x0).
The thread 0x4bb8 has exited with code 0 (0x0).
The thread 0x4bd0 has exited with code 0 (0x0).
The thread 0x4ba4 has exited with code 0 (0x0).
The thread 0x4be0 has exited with code 0 (0x0).
The thread 0x2b40 has exited with code 0 (0x0).
The thread 0x4bac has exited with code 0 (0x0).
The thread 0x4ba8 has exited with code 0 (0x0).
The program '[19144] opengl_project.exe' has exited with code 0 (0x0).

Могу ли я узнать, почему это происходит? и как это исправить?

При удалении строки glfwSwapBuffers(window); ошибка не выдает.

update

Я добавил строку в while (!glfwWindowShouldClose(window)) l oop чтобы изменить бит чистого цвета: glClearColor(1, 0, 0, 1); до glClear(GL_COLOR_BUFFER_BIT); Но цвет экрана не меняется.

Я обнаружил, что первое сообщение об ошибке генерируется из первой итерации в glfwPollEvents();. Вторая итерация не генерирует никаких сообщений об ошибках, и начиная с третьей итерации строка glfwSwapBuffers(window); будет генерировать одно и то же сообщение об ошибке при каждом вызове.

update 2

Отладчик сообщает что это происходит от d3d11.dll CDevice::OpenSharedResource().

...