Search Unity

VideoPlayer crashes when videos finish playing - 5.6.2

Discussion in 'Android' started by jason_yak, Jun 27, 2017.

  1. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    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?

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

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    I load and instantiate a prefab that's been preconfigured with the videoclip and uses audio source mode.

    Code (CSharp):
    1. var vidPrefab = Resources.Load<GameObject>( path );
    2. videoPlayer = ( Instantiate( vidPrefab ) as GameObject ).GetComponent<VideoPlayer>();
    3. videoPlayer.gameObject.name = vidPrefab.name;
    4. videoPlayer.transform.parent = transform;
    5. videoPlayer.targetCamera = gameCamera.GetComponent<Camera>();
    6. videoPlayer.prepareCompleted += vidPrepareCompleted;
    7. videoPlayer.started += vidStarted;
    8. videoPlayer.loopPointReached += vidLoopPointReached;
    9. videoPlayer.errorReceived += vidErrorReceived;
    10. videoPlayer.Prepare();
    Code (CSharp):
    1. private void vidPrepareCompleted ( VideoPlayer player ) {
    2.     if ( videoPlayer != null && !videoPlayer.isPlaying ){
    3.         videoPlayer.Play();
    4.     }
    5. }
    6.  
    7. private void vidStarted ( VideoPlayer player ) {
    8.     if ( subtitlesTween == null ){
    9.         displaySubtitles( currentSubtitleText, currentSubtitleTimes );
    10.     }
    11. }
    12.  
    13. private void vidLoopPointReached ( VideoPlayer player ) {
    14.     onVideoComplete();
    15. }
    16.  
    17. private void vidErrorReceived ( VideoPlayer source, string message ) {
    18.     Debug.LogError( "VID ERROR: " + message );
    19.     onVideoComplete();
    20. }
    Code (CSharp):
    1. public void onVideoComplete () {
    2.     removeSubtitlesTween();
    3.     if ( videoPlayer != null ) {
    4.         videoPlayer.prepareCompleted -= vidPrepareCompleted;
    5.         videoPlayer.started -= vidStarted;
    6.         videoPlayer.loopPointReached -= vidLoopPointReached;
    7.         videoPlayer.errorReceived -= vidErrorReceived;
    8.         if ( videoPlayer.isPlaying ){
    9.             //videoPlayer.Stop(); // <-- tried with and without this
    10.         }
    11.         Destroy( videoPlayer.gameObject );
    12.         videoPlayer = null;
    13.     }
    14. }
     
  3. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    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.

    Code (CSharp):
    1. StartCoroutine( removeAfterDelay( videoPlayer ) );
    2. //Destroy( videoPlayer.gameObject ); // if called in loopPointReached event causes a crash on Android
    3. videoPlayer = null;
    4.  
    5. private IEnumerator removeAfterDelay ( VideoPlayer vid ) {
    6.     yield return null;
    7.     if ( vid != null ){
    8.         Destroy( vid );
    9.         vid = null;
    10.     }
    11. }
     
  4. slimatt

    slimatt

    Joined:
    Oct 9, 2015
    Posts:
    2
    I can reproduce this as well. Crashes the windows editor with 5.6.2. The fix also works (thanks for that).
     
  5. US_Alexphauge

    US_Alexphauge

    Joined:
    Jun 13, 2017
    Posts:
    1
    This also happened to us, and we are very grateful for the workaround as that helped us.
     
  6. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    183
    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.
     
  7. anthony707

    anthony707

    Joined:
    Nov 25, 2014
    Posts:
    1
    Unregistering from loopPointReached and checking current frame manually seems to resolve the crashes.

    Thanks for the hints.
     
    passerbycmc likes this.