当我运行以下代码(或我尝试过的任何变体)时,我得到一个总线错误。它编译得很好。
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <fstream>
#include <iostream>
#include <stream>
void main() {
/* * * * * * * * * * * * * * * * * *
* Code that loads the shader file.*
* This works fine, error is later.*
* * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * *
* Code that generates OpenGL *
* shader and compiles it. Works. *
* * * * * * * * * * * * * * * * * */
// Check for errors compiling shader
bool status;
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &status);
if(status == GL_FALSE) {
// Compiler errors
GLchar* log = (GLchar*) "\0";
GLint len = 0;
GLint rLen = 0;
glGetShaderiv(this->shaderId, GL_INFO_LOG_LENGTH, &len);
// Next line causes bus error 10
glGetShaderInfoLog(this->shaderId, len, &rLen, log);
std::cerr << "Error compiling shader: " << this->filename << ":\n\t" << log << std::endl;
}
}
我在 Mac OSX 上运行它。如果 glGetShaderInfoLog 被注释掉,它工作正常(虽然 glGetProgramInfoLog 会导致相同的错误)。这是崩溃报告中的一些重要信息。
异常类型:EXC_BAD_ACCESS (SIGBUS)
异常代码:0x000000010cd5c0f0 处的 KERN_PROTECTION_FAILURE
异常说明:EXC_CORPSE_NOTIFY
终止信号:总线错误:10
终止原因:命名空间 SIGNAL,代码 0xa
终止进程:exc 处理程序 [0]
0x10cd5c0f0 附近的 VM 区域:
--> __TEXT 000000010ccc4000-000000010cd5f000 [ 620K] rx/rwx SM=COW /Users/USER/*
__DATA 000000010cd5f000-000000010cd64000 [ 20K] rw-/rwx SM=COW /Users/USER/*
0 libsystem_platform.dylib 0x00007fffcc50fefc _platform_memmove$VARIANT$Haswell + 92
1 GLEngine 0x00007fffbbeda274 gleGetString + 52
2 GLEngine 0x00007fffbbe22d20 glGetShaderInfoLog_Exec + 141
3 程序 0x000000010cd357af 着色器::validate() + 127
4 程序 0x000000010cd35575 着色器::compile() + 1621
5 程序 0x000000010cd349ed 程序::link() + 45
6 程序 0x000000010cd3235e 对象::对象(char*, char*, char*, char*) + 222
7 程序 0x000000010cd32c65 对象::对象(char*, char*, char*, char*) + 53
8 程序 0x000000010cd2e7c0 主要 + 4576
9 libdyld.dylib 0x00007fffcc2ff255 开始 + 1