首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android SurfaceView仿真程序OpenGL错误

Android SurfaceView仿真程序OpenGL错误
EN

Stack Overflow用户
提问于 2018-01-04 14:30:16
回答 1查看 5.5K关注 0票数 7

当运行简单的代码在SurfaceView中绘制时,我在Android模拟器中得到了几个SurfaceView错误。因此,在模拟器中运行时,SurfaceView不会绘制。相同的代码在设备上正确运行(在本例中,是Amazon 8 (2017 - KFDOWI))。

以下是错误:

模拟器: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glReadPixels:2827错误0x502 模拟器: sPrepareTexImage2D:3087失败验证 模拟器: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133错误0x500 模拟器: sPrepareTexImage2D:3087失败验证 模拟器: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexImage2D:3133错误0x500 模拟器: android/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glTexSubImage2D:3237错误0x500

以下是代码:

代码语言:javascript
复制
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) {
    }
}

活动:

代码语言:javascript
复制
<?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高塞拉10.13.2
  • 16 GB RAM
  • Android Studio 3.0.1
  • JRE 1.8.0_152
  • HAXM 6.2.1

AVD信息:

  • API 25
  • 图形:自动
  • RAM: 1536 MB

应用程序信息:

  • API 26
  • Min SDK: 19

此外,我可以在同一个模拟器中运行OpenGL es2.0代码,而不会出现这些问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-25 03:06:08

停止硬件加速。

打开虚拟设备配置->编辑虚拟设备->使用软件模式图形

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48097399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档