OpenGL getShaderInfoLog Bus Error 10



当我运行以下代码(或我尝试过的任何变体)时,我会遇到总线错误。它可以很好地编译。

#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*) "";
        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 << ":nt" << log << std::endl;
    }
}

我正在Mac OSX上运行它。如果将GLGETSHADERINFOLOG评论出来(GlgetPrograminfolog虽然导致相同的错误),则可以正常工作。这是崩溃报告中一些重要的外观信息。

异常类型:exc_bad_access(sigbus)

异常代码:kern_protection_failure在0x000000010cd5c0f0

异常注意:exc_corpse_notify

终止信号:总线错误:10

终止原因:名称空间信号,代码0xa

终止过程:EXC处理程序[0]

VM区域附近0x10CD5C0F0:

- &gt;__TEXT 000000010CCCCCCCCCCCCCCCCCCCCCCCCCCD5F000 [620K] R-X/RWX SM = Cow/user/user/user/*

__数据000000010CD5F000-000000010CD64000 [20K] RW-/RWX SM = Cow/user/user/user/*

0 libsystem_platform.dylib 0x00007ffc50fefc _platform_memmove $ variant $ haswell 92

1 Glengine 0x00007fffbbeda274 glegetstring 52

2 Glengine 0x00007FFFBBE22D20 GLGETSHADERINFOLOG_EXEC 141

3程序0x000000010CD357AF着色器:: Validate() 127

4程序0x000000010CD35575 Shader :: Compile() 1621

5程序0x000000010CD349ED程序:: link() 45

6程序0x000000010CD3235E对象:: object(char*,char*,char*,char*,char*) 222

7程序0x000000010CD32C65对象:: object(char*,char*,char*,char*,char*) 53

8程序0x000000010CD2E7C0主 4576

9 libdyld.dylib 0x00007fffcc2ff255开始 1

glGetShaderInfoLog的最后一个参数告诉它在哪里写日志。您将其传递给字符串字面""。您正在告诉它用日志文件覆盖此字符串。

覆盖字符串文字是未定义的行为;实际上,它通常会导致您的程序崩溃。即使您可以覆盖它,您还是没有提供足够的空间。

您应该分配一些空间来持有日志。这样的东西:

glGetShaderiv(this->shaderId, GL_INFO_LOG_LENGTH, &len);
vector<char> log(len);
glGetShaderInfoLog(this->shaderId, log.size(), &rLen, log.data());
// to get the log as a C string use log.data()

相关内容

  • 没有找到相关文章

最新更新