gpt4 book ai didi

c++ - EXC_BAD_ACCESS glGetShaderInfoLog - 如何进行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:24:43 25 4
gpt4 key购买 nike

我正在使用 Marmalade C++ 和 Open GL ES 2.0。我正在学习几个教程,但总是遇到同样的错误:

调用 glGetShaderInfo() 时出现 EXC_BAD_ACCESS

这是我的代码。在这种情况下我该如何处理?

static int eglInit()
{
if (!IwGLInit() )
{
s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "eglInit failed");
return 1;
}
return 0;
}

const char* vShaderStr =
"attribute vec4 vPosition;\n"
"void main()\n"
"{\n"
"gl_Position = vPosition;\n"
"};\n";

const char* fShaderStr =
"precision mediump float;\n"
"void main()\n"
"{\n"
"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
"}\n";

GLuint LoadShader(GLenum type, const char *shaderSrc)
{
GLuint shader;
GLint compiled;

// Create the shader object
shader = glCreateShader(type);

if (shader == 0)
return 0;

// Load the shader source
glShaderSource(shader, 1, &shaderSrc, NULL);

// Compile the shader
glCompileShader(shader);

glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);

if (!compiled)
{
GLint infoLen = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
if (infoLen > 1)
{
char* infoLog = (char*)malloc(sizeof(char) * infoLen);

glGetShaderInfoLog(shader, infoLen, NULL, infoLog);
printf("Error compiling shader:\n%s\n", infoLog);

free(infoLog);
}

glDeleteShader(shader);
return 0;
}

return shader;
}

int main()
{
if (eglInit())
return 1;
printf("Screen BPP: %d\n", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK);
printf("\n");
printf( "Vendor : %s\n", (char*)glGetString(GL_VENDOR));
printf( "Renderer : %s\n", (char*)glGetString(GL_RENDERER));
printf( "Version : %s\n", (char*)glGetString(GL_VERSION));
printf( "Extensions : %s\n", (char*)glGetString(GL_EXTENSIONS));
printf("\n");

GLuint vertexShader;
vertexShader = LoadShader(GL_VERTEX_SHADER, vShaderStr);

bool quit = false;
int numFrames = 0;
while (!quit) {
s3eKeyboardUpdate();
s3eDeviceYield(0);
if (s3eDeviceCheckQuitRequest())
quit = 1;
if (s3eKeyboardGetState(s3eKeyEsc) & S3E_KEY_STATE_PRESSED)
quit = 1;
numFrames++;
}
//Shutdown GL system
IwGLTerminate();
return 0;
}

最佳答案

在:

glGetShaderInfoLog(shader, infoLen, NULL, infoLog);

您传递的是 NULL 作为第三个参数,它应该接受 GLsizei*。这个参数(第三个)is populated具有信息日志的实际长度,因此应该是一个有效的指针。

要解决您可以做的问题:

GLsizei info_length = 0;
glGetShaderInfoLog(shader, infoLen, &info_length, infoLog);

关于c++ - EXC_BAD_ACCESS glGetShaderInfoLog - 如何进行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21071815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com