VideoPlayer crashes when videos finish playing - 5.6.2

Hi there,

I’ve tried a lot of things to get the new Unity VideoPlayer to work on Android but it keeps crashing for me every time a video finishes playing. I’m using the latest Unity 5.6.2. I’m getting the result on both of my test devices Samsung S2 Tab running Android 6 and Samsung S5 running Android 5. My min support API level is 19 if thats relevant. I haven’t had a chance to break out the code to submit a bug report yet, but following this is a logcat dump of the crash. I’ve found other threads complaining of the same thing where someone mentioned that calling Stop() could cause a crash, I removed this it doesn’t help. I’ll also paste in my play code as well. Any ideas?

D/ActivityManager( 3252): startService callerProcessName:com.google.android.gms, calleePkgName: com.google.android.gms
D/ActivityManager( 3252): retrieveServiceLocked(): component = com.google.android.gms/com.google.android.gms.lockbox.LockboxService; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): caller:android.app.ApplicationThreadProxy@1c0acd3d, r.packageName :com.google.android.gms
D/ActivityManager( 3252): retrieveServiceLocked(): component = null; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): retrieveServiceLocked(): component = null; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): retrieveServiceLocked(): component = null; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): retrieveServiceLocked(): component = null; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): retrieveServiceLocked(): component = null; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): startService callerProcessName:com.google.android.gms, calleePkgName: com.google.android.gms
D/ActivityManager( 3252): retrieveServiceLocked(): component = com.google.android.gms/com.google.android.gms.udc.service.UdcApiService; callingUser = 0; userId(target) = 0
D/ActivityManager( 3252): caller:android.app.ApplicationThreadProxy@1c0142e2, r.packageName :com.google.android.gms
I/DEBUG   ( 2598): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   ( 2598): Build fingerprint: 'samsung/gts28wifixx/gts28wifi:5.0.2/LRX22G/T710XXU2APB2:user/release-keys'
I/DEBUG   ( 2598): Revision: '8'
I/DEBUG   ( 2598): ABI: 'arm'
I/DEBUG   ( 2598): pid: 8569, tid: 8633, name: Thread-5060  >>> co.yakand.agenta <<<
I/DEBUG   ( 2598): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
I/DEBUG   ( 2598):     r0 00000000  r1 963ffdb0  r2 0000000a  r3 00b450b0
I/DEBUG   ( 2598):     r4 af28c920  r5 00000000  r6 00000000  r7 00000003
I/DEBUG   ( 2598):     r8 af28c964  r9 00000003  sl 0000000b  fp af040840
I/DEBUG   ( 2598):     ip a0017a84  sp 963ff820  lr 9f35f824  pc 9f4d2888  cpsr 800f0010
I/DEBUG   ( 2598):
I/DEBUG   ( 2598): backtrace:
I/DEBUG   ( 2598):     #00 pc 00630888  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #01 pc 00630d80  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #02 pc 00620df4  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #03 pc 004c3100  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #04 pc 00564534  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #05 pc 005663c4  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #06 pc 0056035c  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #07 pc 003c8520  /data/app/co.yakand.agenta-2/lib/arm/libunity.so
I/DEBUG   ( 2598):     #08 pc 00016bbb  /system/lib/libc.so (__pthread_start(void*)+30)
I/DEBUG   ( 2598):     #09 pc 00014c83  /system/lib/libc.so (__start_thread+6)
W/ActivityManager( 3252):   Force finishing activity co.yakand.agenta/com.prime31.UnityPlayerNativeActivity
I/DEBUG   ( 2598):
I/DEBUG   ( 2598): Tombstone written to: /data/tombstones/tombstone_04

I load and instantiate a prefab that’s been preconfigured with the videoclip and uses audio source mode.

var vidPrefab = Resources.Load<GameObject>( path );
videoPlayer = ( Instantiate( vidPrefab ) as GameObject ).GetComponent<VideoPlayer>();
videoPlayer.gameObject.name = vidPrefab.name;
videoPlayer.transform.parent = transform;
videoPlayer.targetCamera = gameCamera.GetComponent<Camera>();
videoPlayer.prepareCompleted += vidPrepareCompleted;
videoPlayer.started += vidStarted;
videoPlayer.loopPointReached += vidLoopPointReached;
videoPlayer.errorReceived += vidErrorReceived;
videoPlayer.Prepare();
private void vidPrepareCompleted ( VideoPlayer player ) {
    if ( videoPlayer != null && !videoPlayer.isPlaying ){
        videoPlayer.Play();
    }
}

private void vidStarted ( VideoPlayer player ) {
    if ( subtitlesTween == null ){
        displaySubtitles( currentSubtitleText, currentSubtitleTimes );
    }
}

private void vidLoopPointReached ( VideoPlayer player ) {
    onVideoComplete();
}

private void vidErrorReceived ( VideoPlayer source, string message ) {
    Debug.LogError( "VID ERROR: " + message );
    onVideoComplete();
}
public void onVideoComplete () {
    removeSubtitlesTween();
    if ( videoPlayer != null ) {
        videoPlayer.prepareCompleted -= vidPrepareCompleted;
        videoPlayer.started -= vidStarted;
        videoPlayer.loopPointReached -= vidLoopPointReached;
        videoPlayer.errorReceived -= vidErrorReceived;
        if ( videoPlayer.isPlaying ){
            //videoPlayer.Stop(); // <-- tried with and without this
        }
        Destroy( videoPlayer.gameObject );
        videoPlayer = null;
    }
}

I should add that the above code works fine on iOS and in the editor.

Soooo… I just found a workaround. I did a test where I omitted the line to Destroy( videoPlayer.gameObject ) in the video complete event and it doesn’t crash. So then I’ve modified the code to clean up the video player with a frame delay and it’s not crashing. I’m guessing there’s some code in the video player thats not checking if its been cleaned up after the loopPointReached is fired off. Can anyone at Unity confirm this? Thanks.

StartCoroutine( removeAfterDelay( videoPlayer ) );
//Destroy( videoPlayer.gameObject ); // if called in loopPointReached event causes a crash on Android
videoPlayer = null;

private IEnumerator removeAfterDelay ( VideoPlayer vid ) {
    yield return null;
    if ( vid != null ){
        Destroy( vid );
        vid = null;
    }
}

I can reproduce this as well. Crashes the windows editor with 5.6.2. The fix also works (thanks for that).

This also happened to us, and we are very grateful for the workaround as that helped us.

Thank you for this. This happened to us as well, but I’d like to add that in my case, delaying the Destroy didn’t help. I have to remove any callback I added to loopPointReached as well, otherwise it will crash on Android.

Unregistering from loopPointReached and checking current frame manually seems to resolve the crashes.

Thanks for the hints.

1 Like