我正在使用 Visual Studio 2019,并有以下简单的 OpenGL 程序作为最小示例(使用 GLFW 和 GLAD):
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
void error_callback(int error, const char* description) {
std::cout << "GLFW error: " << description << " (" << error << ")\n";
}
int main() {
if (!glfwInit()) exit(-1);
glfwSetErrorCallback(error_callback);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(640, 480, "GLFW Test Application", nullptr, nullptr);
if (!window) exit(-1);
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) exit(-1);
glViewport(0, 0, 640, 480);
glClearColor(0.6f, 0.6f, 0.1f, 1.f);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
该程序运行良好,但在运行时,我会在调试输出窗口中以几秒到大约 20 秒甚至更多秒的间隔得到类似的行:
Exception thrown at 0x00007FFE61EEA799 (KernelBase.dll) in vcpkg_test.exe: 0x0EEDFADE (parameters: 0x0000000001D0A34E, 0x000001C13E322BA0, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000).
Exception thrown at 0x00007FFE61EEA799 (KernelBase.dll) in vcpkg_test.exe: 0x0EEDFADE (parameters: 0x0000000001D0A34E, 0x000001C13DC7CE40, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000).
Exception thrown at 0x00007FFE61EEA799 (KernelBase.dll) in vcpkg_test.exe: 0x0EEDFADE (parameters: 0x0000000001D0A34E, 0x000001C13DC7CDE0, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000).
该程序继续运行,运行良好,并且退出代码为 0。当我在 Visual Studio 之外执行 EXE 文件时,它也运行良好。当我将 VS 设置为中断所有异常时,我看到异常发生在此调用中(win32_init.c,“createHelperWindow”方法):
_glfw.win32.helperWindowHandle =
CreateWindowExW(WS_EX_OVERLAPPEDWINDOW,
_GLFW_WNDCLASSNAME,
L"GLFW message window",
WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
0, 0, 1, 1,
NULL, NULL,
GetModuleHandleW(NULL),
NULL);
我已经在谷歌上花了几个小时试图找到解决方案。我得到的唯一“提示”是当我以管理员身份运行 VS19 时不会发生异常。有人知道是什么原因造成的吗?或者我应该忽略它,因为它运行良好?不过那感觉不对……
更新/解决方案
我遵循了本回答中的提示(请参阅接受的答案)。在对第一次机会异常启用中断后,我得到了以下堆栈跟踪:
DLL“ammemb64.dll”也出现在模块窗口中。它属于“Actual Multiple Monitors”软件,关闭该应用程序后,异常消失了。