UnityPlugin-AVProVideo icon indicating copy to clipboard operation
UnityPlugin-AVProVideo copied to clipboard

Crash using short videos in Playlist Demo Scene

Open Helath2605 opened this issue 1 year ago • 24 comments

Please DO NOT LINK / ATTACH YOUR PROJECT FILES HERE

Describe the issue Replacing the videos in the demo scene with short looping videos causes unity to crash after a while. The demo videos seem to work fine, and only happens when using either short videos, or maybe something with how we are exporting them.

Your Setup (please complete the following information):

  • Unity version: v2022.3.7f1 WindowsEditor
  • AVPro Video version (number and edition (trial/core/ultra/enterprise)): v3.0.8 (plugin v3.0.8f1-core)
  • Operating system version: Windows 10 19044.4780
  • Video specs (resolution, frame-rate, codec, file size): -6 videos across two displays. -All at 1920x2160 and around 30fps frame rates. -.mp4 extensions
    • all videos less than 6MB

To Reproduce

  1. Open Demo Scene
  2. Set Windows platform Settings to the following -WinRT API -Hardware Decoding enabled -Use Render Sync off
  3. Set to play short videos (1-2 seconds)
  4. Will crash within 12 hours

Logs Crash.txt I can post the full log and dump if needed.

Helath2605 avatar Aug 27 '24 20:08 Helath2605

Does the issue occur using MediaFoundation and DirectShow API? Are you able to provide the video(s) you are using for testing please? either here or to [email protected]

Chris-RH avatar Sep 02 '24 10:09 Chris-RH

Just a slight side note here that 'Hardware Decoding' and 'Render Sync' only affect Media Foundation playback, not WinRT (which has relatively few options)

RichRH avatar Sep 02 '24 14:09 RichRH

Email sent, relevant info in the copy: In the Demo scenes folder I duplicated and modified the playlist scene to allow 2 monitors and multiple videos. The scene is called Demo_Playlist_Modded and it is the one that is crashing. Is also has a button to swap scenes since we noticed that for Media Foundation the graphics driver would crash at some point, but unity would still work until you tried to change scenes and it would crash. No useful information from the unity logs except for reports of dx11 unable to create textures and just an 887A0006 error from windows event logs.

Helath2605 avatar Sep 04 '24 14:09 Helath2605

Hi @Helath2605,

Thanks for sending this through - I just wanted to check a couple of things..

  1. If I load your test scene and play in editor the video only seems to play once (no looping) - should I be doing something else? (Does it need to be a build?)
  2. It currently seems to be using WinRT for playback - is that where you're seeing the crash as you mention MF in the above post?

Cheers,

RichRH avatar Sep 05 '24 14:09 RichRH

It will loop correctly in the build, but if you wanted to run it in the editor, forcing it to go to the next item via the bottom of the "Playlist Media Player" will make it loop correctly for the rest. Not an intended result, and I have no idea why the first video has an issue in the editor. I don't believe the build I sent you has any modifications to the demo "Playlist Media Player".

I have tried all 3 APIs with that scene. WinRT was my last test where I would get the Crash log in the original post. The MF reference was just additional data in case it helps.

Helath2605 avatar Sep 05 '24 14:09 Helath2605

Thanks for the confirmation @Helath2605 - I actually found both editor and build wouldn't advance past the first video for me if using WinRT (MF would), but I've found a possible cause and added a fix that should make it into the next release.

Will leave the build running overnight with a debug version of AVPro to see if I can catch any crashes..

RichRH avatar Sep 05 '24 16:09 RichRH

Hi @Helath2605,

FYI.. we're hoping to release a build today that should fix the WinRT first-time looping issue.

I ran your WinRT build overnight though the debugger and did encounter a crash - it seemed to fail within the allocation of WinRT's internal video player with an out of memory exception, but the process itself was only using about 160Mb so there's the possibility it's something more at system level.

I'll keep investigating but this might take some time - you might want to keep an eye on https://github.com/RenderHeads/UnityPlugin-AVProVideo/issues/1692, especially the last few posts, as yours seems to be a similar issue to TatsuyaPan (I may merge the two issues). Note they've had similar issues with the Unity video player itself which may also suggest more system-level problems, and it seems the most stablity for small/looping videos currently comes from Media Foundation without 'Hardware Acceleration' enabled.

Cheers,

RichRH avatar Sep 06 '24 09:09 RichRH

AVPro Video version 3.0.10 has been released. Please update and retest to see if there is any improvement.

Chris-RH avatar Sep 06 '24 14:09 Chris-RH

Still crashing, but this time it's actually reporting the memory leak to task manager. In the demo project I sent you I updated to 3.0.10 and made it run the Demo_Playlist_Modded scene. Changed the active players to Media Foundation and turned Hardware Acceleration and RenderSync off. In about an hour the Project crash and was using 10GB of RAM.

Helath2605 avatar Sep 09 '24 13:09 Helath2605

Hi @Helath2605,

Thanks for the update - just to confirm, the only fix in version 3.0.10 related to this issue is for WinRT failing to loop. I'm still looking into the crash side of things.

Cheers,

RichRH avatar Sep 09 '24 14:09 RichRH

Not sure if this helps, but it seems as though just repeatedly opening and closing videos will cause a leak as well. And it that is the case it would make sense why we might be seeing it with shorter videos that rapidly open and close.

This is the script I used

using RenderHeads.Media.AVProVideo;
using System.Collections;
using UnityEngine;

public class QuickLoadAndUnload : MonoBehaviour
{
    [SerializeField] MediaPlayer Player;

    void Start()
    {
        StartCoroutine(Run());
    }

    IEnumerator Run()
    {
        while (true)
        {
            Player.OpenMedia(new MediaPath("AVProVideoSamples/RenderHeads-1080p30-H264.mp4", MediaPathType.RelativeToStreamingAssetsFolder), false);
            yield return new WaitForSeconds(1);
            Player.CloseMedia();
            yield return new WaitForSeconds(1);
        }
    }
}

Settings: image

And in about 30 mins we were already using over 2GB on the target machine. Can also see a leak in the editor.

Helath2605 avatar Sep 11 '24 16:09 Helath2605

Hey, has there been any updates for this issue?

Helath2605 avatar Sep 16 '24 19:09 Helath2605

We'll update this thread when we have any news :)

Chris-RH avatar Sep 17 '24 07:09 Chris-RH

Hi @Helath2605,

Quick update - I believe I've located a fairly major leak in Unity (and the way it wraps native textures) linked to the above, at least with rapid loading of videos under MF (not sure it'll impact WinRT). I'm looking into fixing/compensating for it at native level and will update this ticket when I have more information.

Cheers,

RichRH avatar Sep 17 '24 16:09 RichRH

Hi @Helath2605,

Another update - I've tracked down a separate leak in WinRT/Windows which was causing the above crash and have added a workaround which will be in the next release (as well as the MF leak fix - hopefully within the next week).

Cheers,

RichRH avatar Sep 20 '24 13:09 RichRH

Looking forward to the MF leak fix! Here from #1736

wybo avatar Sep 20 '24 22:09 wybo

Any chance the 3.0.12 update can be done soon, as it would be great to finally be rid of the memory leak!

wybo avatar Sep 28 '24 01:09 wybo

I would also love an update if there is one :)

Helath2605 avatar Oct 02 '24 14:10 Helath2605

@wybo @Helath2605 We are aiming to release the next update this coming Friday. Currently this will be 3.1.0. We will message this thread when we get the release out. Sorry for the delay.

Ste-RH avatar Oct 02 '24 16:10 Ste-RH

Great to hear!

Especially hope the Media Foundation fix will work with hardware decoding! As some of my users are from Latin America & other areas where they might not have the newest / fastest hardware.

wybo avatar Oct 02 '24 19:10 wybo

Are we still looking for a release soon or is it going to be a while?

Helath2605 avatar Oct 14 '24 13:10 Helath2605

Its looking like mid-end of this week if everything goes well :D

Chris-RH avatar Oct 14 '24 13:10 Chris-RH

Apologies it has not been released yet. We have hit a number of unforeseen issues as we have approached release. These have all taken longer to address than we had hoped. As Chris says...hopefully this week.

Ste-RH avatar Oct 14 '24 14:10 Ste-RH

AVPro Video v3.1.0 has just been released. Please do report back if the fixes in the version address the issue.

Ste-RH avatar Oct 18 '24 16:10 Ste-RH

I've updated to v3.1.0 and ran my app for 3 long sessions. Two of 4 hours, and one of six, and while there's still a small increase of max 300 mb in that timespan (which could be anything else), the main issue of ballooning memory usage by GBs followed by crashes is gone!

Thanks a lot for fixing this!

wybo avatar Oct 22 '24 08:10 wybo

Thanks for letting us know @wybo. Always great to get to the bottom of an issue and get it into developers hands!

If you have a few spare minutes, would you mind dropping us an honest review of the asset and support we offer on the Unity Asset Store? It really helps us to continue updating the asset with new features and offer the level of support we hope helps developers achieve great things with their products/projects. Thanks!

Ste-RH avatar Oct 22 '24 09:10 Ste-RH

Done! https://assetstore.unity.com/packages/tools/video/avpro-video-v3-core-edition-278893#reviews

Am still curious how it was fixed, and especially whether the workaround / fix affects support for hardware decoding or not in Media Foundation

wybo avatar Oct 24 '24 21:10 wybo

Everything I looking good on our end so far as well. Sorry for the late response, we were having weird texture reference issues and I wanted to make sure it wasn't related to the plugin. However it seems to be just a driver issue, so I think we are good!

Helath2605 avatar Oct 24 '24 21:10 Helath2605

@wybo Many thanks for your review. We have left a reply to it with some more information on the fix we had to put in place. Here is the main of that for anyone else interested:

The root cause of the main leak is actually a change Unity themselves made, not something that existed in AVPro Video (historically per se). The change Unity made was regarding how they reference count native (external) textures. We were unaware of the change they made, certainly we could not find any public facing declaration of the change and it may even be a bug in Unity! The change we made at AVPro Video plugin level was to add special case code to handle this change/bug in reference counting. The whole process of getting to a reliable fix was elongated due to this issue only happening in some versions of Unity.

Ste-RH avatar Oct 25 '24 08:10 Ste-RH