设备:三星 Galaxy Note Android 版本:4.0.4
我的应用程序使用 OpenGL 着色器将一些视觉效果应用于视频流。出于安全原因,我需要使用二进制着色器。我正在使用glSurfaceView
和SurfaceTexture
访问 OpenGL 着色器中的帧数据并使用扩展名GL_OES_EGL_image_external
. 就我使用着色器源而言,这工作正常。当我尝试使用已编译的着色器二进制文件时,我经常遇到错误A/libc(4242): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1)
并且程序崩溃。当我尝试使用返回键关闭应用程序时它正在工作时,我通常会收到错误消息
A/libc(4907): @@@ ABORTING: INVALID HEAP ADDRESS IN dlfree
我尝试在 android xref 的本机媒体示例应用程序中使用二进制着色器: http ://androidxref.com/source/xref/development/ndk/platforms/android-14/samples/native-media/
我得到同样的错误。
我正在使用 ARM malisc 提供的编译器创建二进制着色器,我用于加载二进制文件的代码是
private int ShaderFromBIN(Resources resource) {
IntBuffer vert2 = IntBuffer.allocate(1);
IntBuffer frag2 = IntBuffer.allocate(1);
vert2.put(GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER));
frag2.put(GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER));
try {
InputStream in_sv = resource.openRawResource(R.raw.v2);
InputStream in_sf = resource.openRawResource(R.raw.f2);
byte[] bv = new byte [in_sv.available()];
in_sv.read(bv);
//= IOUtils.toByteArray(in_sv);
ByteBuffer bbv = ByteBuffer.wrap(bv);
byte[] bf = new byte [in_sf.available()];
// IOUtils.toByteArray(in_sf);
in_sf.read(bf);
ByteBuffer bbf = ByteBuffer.wrap(bf);
IntBuffer numFormats = IntBuffer.allocate(1);
GLES20.glGetIntegerv(GLES20.GL_NUM_SHADER_BINARY_FORMATS,
numFormats);
IntBuffer formats;
if (numFormats.get(0) > 0) {
formats = IntBuffer.allocate(numFormats.get(0));
GLES20.glGetIntegerv(GLES20.GL_SHADER_BINARY_FORMATS, formats);
for (int i = 0; i < numFormats.get(0); ++i) {
Log.d("format " + i + " ", formats.get(i) + "");
GLES20.glShaderBinary(1, vert2, formats.get(i), bbv, bv.length);
GLES20.glShaderBinary(1, frag2, formats.get(i), bbf, bf.length);
checkGlError("compile vertex shader");
}
}
in_sv.close();
in_sf.close();
bf = null;
bv = null;
} catch (Exception e) {
// e.printStackTrace();
Log.e("Error: can't read resource.", "");
}
sampler_program = GLES20.glCreateProgram();
if (sampler_program != 0) {
GLES20.glAttachShader(sampler_program, vert2.get(0));
checkGlError("glAttachShader");
GLES20.glAttachShader(sampler_program, frag2.get(0));
checkGlError("glAttachShader");
GLES20.glLinkProgram(sampler_program);
checkGlError("glLinkProgram");
int[] linkStatus = new int[1];
GLES20.glGetProgramiv(sampler_program, GLES20.GL_LINK_STATUS,
linkStatus, 0);
if (linkStatus[0] != GLES20.GL_TRUE) {
Log.e(TAG, "Could not link program: ");
Log.e(TAG, GLES20.glGetProgramInfoLog(sampler_program));
GLES20.glDeleteProgram(sampler_program);
sampler_program = 0;
}
}
checkGlError("after linking");
if (sampler_program == 0) {
Log.e(TAG, "Error in creating and compiling the shader programs");
return -1;
}
return sampler_program;
}
我在这个问题上苦苦挣扎了 4 天。我做错什么了吗?请帮我解决这个问题。
谢谢,
达迈克
编辑:
当我使用 ndk-stack 获取崩溃日志时,这就是我得到的
***崩溃转储:** *
Build fingerprint: 'samsung/GT-N7000/GT-N7000:4.0.4/IMM76D/XXLRK:user/release-keys'
pid: 11581, tid: 11594 >>> com.example.nativemedia <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad
Stack frame #00 pc 00017938 /system/lib/libc.so
Stack frame #01 pc 000137c2 /system/lib/libc.so
Stack frame #02 pc 00015b00 /system/lib/libc.so (dlfree)
Stack frame #03 pc 00016178 /system/lib/libc.so (free)
Stack frame #04 pc 00025e04 /system/lib/libMali.so (__mali_program_binary_state_reset)
Stack frame #05 pc 00016068 /system/lib/egl/libGLESv2_mali.so(_gles_program_rendering_state_deref)
Stack frame #06 pc 000281b4 /system/lib/egl/libGLESv2_mali.so_gles2_program_internal_free)
Stack frame #07 pc 00028228 /system/lib/egl/libGLESv2_mali.so(_gles2_program_object_list_entry_delete)
Stack frame #08 pc 0002da9c /system/lib/egl/libGLESv2_mali.so(_gles_share_lists_clear_v2_content)
Stack frame #09 pc 000110d4 /system/lib/egl/libGLESv2_mali.so (_gles_share_lists_deref)
Stack frame #10 pc 00026b88 /system/lib/egl/libGLESv2_mali.so (_gles2_delete_context)
Stack frame #11 pc 00013efc /system/lib/egl/libEGL_mali.so (__egl_gles_release_context)
Stack frame #12 pc 0000b07c /system/lib/egl/libEGL_mali.so (__egl_release_context)
Stack frame #13 pc 0000b0d4 /system/lib/egl/libEGL_mali.so (_egl_destroy_context_internal)
Stack frame #14 pc 0000b6e8 /system/lib/egl/libEGL_mali.so (_egl_destroy_context)
Stack frame #15 pc 0000c720 /system/lib/egl/libEGL_mali.so (eglDestroyContext)
Stack frame #16 pc 0000c346 /system/lib/libEGL.so (eglDestroyContext)
Stack frame #17 pc 0004b67e /system/lib/libandroid_runtime.so
Stack frame #18 pc 0001edb0 /system/lib/libdvm.so (dvmPlatformInvoke)
Stack frame #19 pc 00059168 /system/lib/libdvm.so (_Z16dvmCallJNIMethodPKjP6JValuePK6MethodP6Thread)