Android SurfaceView 模拟器 OpenGL 错误
Android SurfaceView Emulator OpenGL Errors
当 运行 在 SurfaceView 中绘制简单代码时,我在 Android 模拟器中遇到几个 OpenGL 错误。因此,在模拟器中 运行ning 时,SurfaceView 不会绘制。相同的代码 运行s 在设备上正确(在本例中为 Amazon Fire HD 8 (2017 - KFDOWI))。
错误如下:
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glReadPixels:2827 error 0x502
Emulator: sPrepareTexImage2D:3087 failed validation
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133 error 0x500
Emulator: sPrepareTexImage2D:3087 failed validation
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133 error 0x500
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexSubImage2D:3237 error 0x500
代码如下:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder surfaceHolder;
public CustomSurfaceView(Context context) {
super(context);
init();
}
public CustomSurfaceView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init();
}
private void init() {
this.surfaceHolder = getHolder();
surfaceHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
Canvas canvas = surfaceHolder.lockCanvas();
canvas.drawColor(Color.RED);
surfaceHolder.unlockCanvasAndPost(canvas);
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
}
Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<CustomSurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
系统信息:
- MacOS High Sierra 10.13.2
- 16 GB 内存
- Android Studio 3.0.1
- JRE 1.8.0_152
- HAXM 6.2.1
AVD 信息:
- API 25
- 图形:自动
- 内存:1536MB
应用信息:
- API 26
- 最小 SDK:19
此外,我可以在同一个模拟器中 运行 OpenGL ES 2.0 代码而不会出现这些问题。
禁用硬件加速。
[打开虚拟设备配置->编辑虚拟设备->使用软件模式图形]
当 运行 在 SurfaceView 中绘制简单代码时,我在 Android 模拟器中遇到几个 OpenGL 错误。因此,在模拟器中 运行ning 时,SurfaceView 不会绘制。相同的代码 运行s 在设备上正确(在本例中为 Amazon Fire HD 8 (2017 - KFDOWI))。
错误如下:
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glReadPixels:2827 error 0x502
Emulator: sPrepareTexImage2D:3087 failed validation
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133 error 0x500
Emulator: sPrepareTexImage2D:3087 failed validation
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133 error 0x500
Emulator: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexSubImage2D:3237 error 0x500
代码如下:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
private SurfaceHolder surfaceHolder;
public CustomSurfaceView(Context context) {
super(context);
init();
}
public CustomSurfaceView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
init();
}
private void init() {
this.surfaceHolder = getHolder();
surfaceHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
Canvas canvas = surfaceHolder.lockCanvas();
canvas.drawColor(Color.RED);
surfaceHolder.unlockCanvasAndPost(canvas);
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
}
}
Activity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity">
<CustomSurfaceView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
系统信息:
- MacOS High Sierra 10.13.2
- 16 GB 内存
- Android Studio 3.0.1
- JRE 1.8.0_152
- HAXM 6.2.1
AVD 信息:
- API 25
- 图形:自动
- 内存:1536MB
应用信息:
- API 26
- 最小 SDK:19
此外,我可以在同一个模拟器中 运行 OpenGL ES 2.0 代码而不会出现这些问题。
禁用硬件加速。
[打开虚拟设备配置->编辑虚拟设备->使用软件模式图形]