Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SurfaceView Emulator OpenGL Errors

I am getting several OpenGL errors in the Android Emulator when running simple code to draw in a SurfaceView. As a result, the SurfaceView does not draw when running in the emulator. The same code runs correctly on a device (in this case, an Amazon Fire HD 8 (2017 - KFDOWI)).

Here are the errors:

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

Here is the code:

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>

System Information:

  • MacOS High Sierra 10.13.2
  • 16 GB RAM
  • Android Studio 3.0.1
  • JRE 1.8.0_152
  • HAXM 6.2.1

AVD Information:

  • API 25
  • Graphics: Automatic
  • RAM: 1536 MB

App Information:

  • API 26
  • Min SDK: 19

Also, I can run OpenGL ES 2.0 code in this same emulator without these issues.

like image 537
composer314 Avatar asked Jan 04 '18 14:01

composer314


1 Answers

Disable hardware acceleration.

[open virtual device configuration -> edit virtual device -> use software mode graphics]

like image 67
muro Avatar answered Dec 01 '22 18:12

muro