Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android error signal 11 when a movie draws into a canvas

I'm developing an Android application in which I'm trying to display a GIF image. For that I am using the Movie class and created a class GIFView that extends View. I getting a Movie instance from Movie.decodeFile method.

I am getting an error when Movie.draw(canvas) is called.

04-28 13:44:18.001: A/libc(24883): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 24883 (mple.channel002) 

There is the concerned code :

    public void setGif(File gif)
    {
        movie = Movie.decodeFile(gif.getAbsolutePath());
    }

    @Override
    public void draw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.draw(canvas);
        canvas.drawColor(0xFFCC3C6C);            

        if(movie != null)
        {
            if(movieStart == 0)
                movieStart = android.os.SystemClock.uptimeMillis();
            int duration = Math.max(movie.duration(), 1000);
            movie.setTime((int)(duration - ((android.os.SystemClock.uptimeMillis() - movieStart)%duration)));

            movie.draw(canvas, 10, 10);//TODO CRASH

            invalidate();
        }
    }

I create a GIFView in the main, call setGIF method above to give it the path and add it to the layout with FillParent parameter. It works when I print this image in an ImageView. Drawing a drawable in the canvas instead of the GIF works too. So the problem seems to deals with the Movie instance.

I used these links to make the GIFView http://weavora.com/blog/2012/02/07/android-and-how-to-use-animated-gifs/

I also tried it this way but same error on movie.draw Info about the Movie class for Android

EDIT1: I do my tests on an Oppo Find 7a on Android 4.4.2 / snapdragon 801 / 2GB Changing movie.draw(canvas, 10, 10) to movie.draw(canvas, 10f, 10f) doesn't change anything.

EDIT2: I just tested on an old ZTE device with Android 2.3.5 and it worked.. So something is wrong when launching on Find7a device but I can't figure out what :(

like image 879
Vrong Avatar asked Apr 28 '15 12:04

Vrong


2 Answers

I found another solution - you have to disable hardware accelerator only on this specific view you draw movie. Use next line:

view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

Reference (view level) https://developer.android.com/guide/topics/graphics/hardware-accel.html#controlling

like image 130
Iliya Gug Avatar answered Nov 16 '22 05:11

Iliya Gug


FINALLY! I found the answer, it appears that on some Android version or devices hardware acceleration needs to be disabled.
I just added this this to my manifest:

<application android:hardwareAccelerated="true" ...>

More information on using enabling/disabling hardware acceleration can be found here.

like image 37
Vrong Avatar answered Nov 16 '22 06:11

Vrong