MSVC __debugbreak() 与 openGL 错误回调一起使用时不产生调用堆栈
MSVC __debugbreak() when used with openGL error callback produces no callstack
我正在使用 openGL 的最新 glDebugMessageCallback
约定来帮助我处理 openGL 错误。我想要做的是有办法查看导致 openGL 错误的函数。我认为使用回调方法的唯一方法是在我的回调函数中插入一个断点,这样当在 visual studio 内生成错误时,我可以返回并检查调用堆栈以查看到底是什么函数导致了问题:
void GLAPIENTRY MyOpenGLErrorCallbackFunc(GLenum source, GLenum debugErrorType, GLuint errorID, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
{
switch(debugErrorType)
{
case GL_DEBUG_TYPE_ERROR:
{
BGZ_CONSOLE("GL Type error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
{
BGZ_CONSOLE("GL deprecated gl function usage error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
{
BGZ_CONSOLE("GL undefined behavior error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
};
};
但是,当我尝试通过将无效枚举传递给其中一个 openGL 函数来测试它时,程序确实中断了,我的所有调用堆栈显示为:
myProgram.exe!MyOpenGLErrorCallbackFunc(GLenum source, GLenum debugErrorType, GLuint errorID, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
[External code]
所以我的代码没有执行树可供查看。有没有办法让它发挥作用?
您必须启用同步调试输出:
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
如果Debug Output is produced asynchronously, then the debug callback function may be called from a thread other than that in which the commands are execute. See Logging and glEnable
。
我正在使用 openGL 的最新 glDebugMessageCallback
约定来帮助我处理 openGL 错误。我想要做的是有办法查看导致 openGL 错误的函数。我认为使用回调方法的唯一方法是在我的回调函数中插入一个断点,这样当在 visual studio 内生成错误时,我可以返回并检查调用堆栈以查看到底是什么函数导致了问题:
void GLAPIENTRY MyOpenGLErrorCallbackFunc(GLenum source, GLenum debugErrorType, GLuint errorID, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
{
switch(debugErrorType)
{
case GL_DEBUG_TYPE_ERROR:
{
BGZ_CONSOLE("GL Type error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
{
BGZ_CONSOLE("GL deprecated gl function usage error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
{
BGZ_CONSOLE("GL undefined behavior error: %s\nGL error id: %i\n", message, errorID);
#if _MSC_VER
__debugbreak();
#endif
}break;
};
};
但是,当我尝试通过将无效枚举传递给其中一个 openGL 函数来测试它时,程序确实中断了,我的所有调用堆栈显示为:
myProgram.exe!MyOpenGLErrorCallbackFunc(GLenum source, GLenum debugErrorType, GLuint errorID, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
[External code]
所以我的代码没有执行树可供查看。有没有办法让它发挥作用?
您必须启用同步调试输出:
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
如果Debug Output is produced asynchronously, then the debug callback function may be called from a thread other than that in which the commands are execute. See Logging and glEnable
。