3

Device : Samsung Galaxy Note Android version: 4.0.4

My application apply some visual effects to a video stream using OpenGL Shaders. I need to use binary shaders for security reasons. I am using glSurfaceView and SurfaceTexture to access the frame data in OpenGL shaders and using the extension GL_OES_EGL_image_external. This is working fine as far as I am using shader source. When I try to use compiled shader binaries I often get an error A/libc(4242): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1) and the program crashes. When It is working when I try to close the app with back key I usually get the error A/libc(4907): @@@ ABORTING: INVALID HEAP ADDRESS IN dlfree

I tried to use binary shaders in the native-media sample application in android xref : http://androidxref.com/source/xref/development/ndk/platforms/android-14/samples/native-media/

and I get the same errors.

I am creating binary shaders using the compiler provided by ARM malisc and the code I use for loading the binaries are

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;
    }

I am struggling with this problem for 4 days. Am I doing anything wrong? Please help me to sort this issue.

Thank you,

Dhammike

Edit:

When I get the crash log with ndk-stack this is what I get

*** Crash dump: ***

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)
biegleux
  • 12,934
  • 11
  • 42
  • 52
user665277
  • 41
  • 1
  • 1
  • 5
  • After struggling with this problem for some time I found that the problem was with the Mali offline shader compiler. This problem is sorted in the latest offline shadercompiler. – user665277 Mar 07 '13 at 12:15

1 Answers1

3

I once had the same error "ABORTING: INVALID HEAP ADDRESS IN dlfree" in my program.

The issue was nowhere from where the signal was thrown. Rather there was a memory corruption happening at a totally unrelated place in my code.

It took a bit of time for me to figure it out, but fixing the memory corruption fixed this problem. Try to disable parts of your code and locate the memory corruption.

Hope this helps.

CuriousChettai
  • 1,842
  • 1
  • 12
  • 10
  • thank you for the suggestion. I tried this approach and as soon as I comment out the above method ShaderFromBIN(Resources resource), the error goes away. Anyway I will try to check whether there is any memory corruption somewhere else. – user665277 Sep 03 '12 at 11:26