我正在运行最新的Android Studio v0.8,我正在努力让Treasure Hunt Android应用程序样本在我的Note II上运行,经过一些更改,我仍然无法让应用程序工作,我也有已经导入了cardboard.jar库。演示应用程序将在我的手机上启动然后崩溃LogCat上显示的错误是这样的:
07-31 15:28:50.803 19490-19503/com.google.vrtoolkit.cardboard.samples.treasurehunt E/checkGlError﹕ onReadyToDraw: glError INVALID_ENUM
07-31 15:28:50.873 19490-19503/com.google.vrtoolkit.cardboard.samples.treasurehunt E/AndroidRuntime﹕ FATAL EXCEPTION: GLThread 713
Process: com.google.vrtoolkit.cardboard.samples.treasurehunt, PID: 19490
java.lang.RuntimeException: onReadyToDraw: glError INVALID_ENUM
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.checkGLError(MainActivity.java:143)
at com.google.vrtoolkit.cardboard.samples.treasurehunt.MainActivity.onNewFrame(MainActivity.java:311)
at com.google.vrtoolkit.cardboard.CardboardView$StereoRendererHelper.onDrawFrame(CardboardView.java:1129)
at com.google.vrtoolkit.cardboard.CardboardView$RendererHelper.onDrawFrame(CardboardView.java:968)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java)
在MainActivity.java:143
static final void checkGLError(String operationDescription){
//if(Main.DEBUGGING){//only do the program-crashing thing in debug mode. In release mode, try to ride through errors. Replace my boolean with yours.
int errorCode;
while ((errorCode = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
String error;
switch(errorCode) {
case GLES20.GL_INVALID_OPERATION: error="INVALID_OPERATION"; break;
case GLES20.GL_INVALID_ENUM: error="INVALID_ENUM"; break;
case GLES20.GL_INVALID_VALUE: error="INVALID_VALUE"; break;
case GLES20.GL_OUT_OF_MEMORY: error="OUT_OF_MEMORY"; break;
case GLES20.GL_INVALID_FRAMEBUFFER_OPERATION: error="INVALID_FRAMEBUFFER_OPERATION"; break;
default: error="Unknown error code";
}
Log.e("checkGlError", operationDescription + ": glError " + error);
throw new RuntimeException(operationDescription + ": glError " + error);
}
在MainActivity.java:311
@Override
public void onNewFrame(HeadTransform headTransform) {
GLES20.glUseProgram(mGlProgram);
mModelViewProjectionParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVP");
mLightPosParam = GLES20.glGetUniformLocation(mGlProgram, "u_LightPos");
mModelViewParam = GLES20.glGetUniformLocation(mGlProgram, "u_MVMatrix");
mModelParam = GLES20.glGetUniformLocation(mGlProgram, "u_Model");
mIsFloorParam = GLES20.glGetUniformLocation(mGlProgram, "u_IsFloor");
// Build the Model part of the ModelView matrix.
Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);
// Build the camera matrix and apply it to the ModelView.
Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
headTransform.getHeadView(mHeadView, 0);
checkGLError("onReadyToDraw");
}
我所做的更改是在build.gradle
android {
compileSdkVersion 19
buildToolsVersion '19.1.0' -----> previously '19.0.3'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0' -----> previously compile 'com.android.support:support-v4:+'
错误似乎来自:
案例GLES20.GL_INVALID_ENUM:error =“INVALID_ENUM”;
我错过了什么吗?这个错误意味着什么?
答案 0 :(得分:1)
GL_INVALID_ENUM表示传递给其中一个方法的枚举值无效。
以glDrawElements方法为例。
该方法的第一个参数应该是枚举。如果传入除列出的符号常量之外的任何符号常量,则会出现此错误。
某些常量仅在特定版本中可用。
在我过去,这样的错误是由于指定构建始终使用任何依赖项的“最新”版本,解决方案是找出最后一个工作版本并将其锁定在构建文件中。升级是一项刻意的努力,有助于保护您免受前沿库中未知错误的影响。