0

SurfaceView でネイティブ インターフェイスを使用すると、シェーダーのコンパイルが失敗します。

このようにアプリケーションを起動すると、すべて問題ありません。

surfaceView = new mSurfaceView(this);
renderer = new mRender();
surfaceView.setRenderer(renderer);
setContentView(surfaceView);

しかし、インターフェイスを使用したい場合は失敗します。私はこのようなレイアウトを適用しています:

setContentView(R.layout.main);
surfaceView = (mSurfaceView) findViewById(R.id.gl_surface_view);
renderer = new mRender();
surfaceView.setRenderer(renderer);

シェーダーのコンパイル時にアプリがクラッシュします。これは私のコードです:

protected int compileShader(int shaderType, String shaderCode)
{
    int shaderHandle = GLES20.glCreateShader(shaderType);

    if (shaderHandle != 0)
    {
        // Pass in the shader source.
        GLES20.glShaderSource(shaderHandle, shaderCode);

        // Compile the shader.
        GLES20.glCompileShader(shaderHandle);

        // Get the compilation status.
        final int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

        // If the compilation failed, delete the shader.
        if (compileStatus[0] == 0)
        {
            GLES20.glDeleteShader(shaderHandle);
            shaderHandle = 0;
        }
    }

    if (shaderHandle == 0)
    {
        throw new RuntimeException("Error creating shader.");
    }

    return shaderHandle;
}

シェーダーが正常にコンパイルされていないため、shaderHandle が 0 になり、次の行でアプリがクラッシュします。

throw new RuntimeException("Error creating shader.");

レイアウトなしで正常にコンパイルされます。問題は、最初のバリアントで次のようにレイアウトを作成していることだと思います: surfaceView = new mSurfaceView(this); しかし、クラッシュするバリアントでは、次のように作成します。それが原因でクラッシュすると思いますが、理由はわかりません。それは私にとっては問題ないようで、問題は見られません。

これは、main.xml でのサーフェス ビューの外観です。

<engine.core.mSurfaceView
    android:id="@+id/gl_surface_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
4

0 に答える 0