1 #include <stdlib.h>
2 
3 /* void glGetShaderInfoLog ( GLuint shader, GLsizei maxLength, GLsizei* length, GLchar* infoLog ) */
android_glGetShaderInfoLog(JNIEnv * _env,jobject,jint shader)4 static jstring android_glGetShaderInfoLog(JNIEnv *_env, jobject, jint shader) {
5     GLint infoLen = 0;
6     glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
7     if (!infoLen) {
8         infoLen = 512;
9     }
10     char* buf = (char*) malloc(infoLen);
11     if (buf == NULL) {
12         jniThrowException(_env, "java/lang/IllegalArgumentException", "out of memory");
13         return NULL;
14     }
15     GLsizei outLen = 0;
16     glGetShaderInfoLog(shader, infoLen, &outLen, buf);
17     jstring result = _env->NewStringUTF(outLen == 0 ? "" : buf);
18     free(buf);
19     return result;
20 }
21