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

Big Memory Leak on Windows [Bug]

Open JavenRT opened this issue 1 year ago • 13 comments

Unity Version

2023.1.20f1

AVPro Movie Capture Version

5.2.4

Which platform(s) are you using?

Windows

Which OS version(s) are you using?

Windows 11

Which rendering API(s) are you using?

Direct3D 12

Hardware

Processor: 13th Gen Intel(R) Core(TM) i9-13900HX 2.20 GHz Installed RAM: 32.0 GB (31.7 GB usable) System type: 64-bit operating system, x64-based processor

Which capture component are you using?

Capture From Texture

Capture mode

Realtime

Which output mode are you using?

Video file

Video codecs

H264

Audio source

Unity

Audio codecs

AAC

Any other component configuration

Frame Rate: 30 Source Texture: camera.targetTexture Camera Render Resolution: HD_1920x1080 Output Target: Video File

The issue

We use a video recorder script that creates videos using this package, the videos are tours of a room and an audio clip is played through unity over the top. This functions perfectly fine on our Mac platform. On Windows however, it only works well the first time, if a second video is recorded we incur a memory leak of a few hundred mb every second, until we reach max memory and the application crashes. This occurs in builds, but also in editor. On occasion the leak does stop however the accrued memory is not released at any point. Additionally we have had builds were this issue was not present. After memory profiling we can see the memory is classed as untracked memory, meaning it must not be managed by the Unity Memory Management API (attached). It appears in private and system heap. We initially used an older version of the package but after trying the newest one 5.2.4, the issue persisted. Build 1 build 2 image

Log output

No response

JavenRT avatar Jun 10 '24 15:06 JavenRT

I should mention, we destroy the CaptureFromTexture object between each recording. And add the component again when it is time to record another.

JavenRT avatar Jun 10 '24 15:06 JavenRT

Hi We also run in this memory problem on windows. Is there any update on above?

richard12121212 avatar Dec 11 '24 01:12 richard12121212

Not at the moment.

Chris-RH avatar Dec 13 '24 07:12 Chris-RH

Hi @JavenRT and @richard12121212,

Apologies this has taken a while to look into.

I'm testing using Unity 6 (6000.0.31f1), D3D12, latest AVPro Movie Capture (5.3.3 - albeit debug build) and our 'Demo01-TextureCapture' scene in editor.

So far I'm not seeing any obvious memory leak - either by making multiple captures within the same play session or play/capture/stop/play/capture/stop etc..

A few questions whilst I keep digging:

  • Have you tried the latest Unity 6? (I've noticed Unity itself leaks quite a lot of D3D12 resources)
  • Have you tried the latest AVPro Movie Capture? (We've fixed a few memory leaks in our other products recently, some in shared code)
  • Can you reproduce the issue in our 'Demo01-TextureCapture' scene?
  • Does the issue occur with D3D11?
  • Does the issue occur if you use say H.264 instead of H.265?
  • Does the issue occur if you don't capture audio?

Apologies for all the questions but trying to narrow it down..

Cheers,

RichRH avatar Dec 17 '24 16:12 RichRH

@RichRH This turned out to be user error for us we believe. It was found that we had two active Cinemachine brains in the scene which seems to cause the leak. Since fixing this we have not encountered the issue. At the time I had found that it was memory not managed by Unity so it's possible it's still related to this package but not something that can be encountered during normal use.

If it helps we did try the latest package available when the bug was reported and we did also disable audio but neither fixed the issue.

JavenRT avatar Dec 17 '24 16:12 JavenRT

Thanks for the confirmation @JavenRT - good to know no longer an issue for you.

Would be great if you could provide any further information (as listed above) @richard12121212..

Cheers,

RichRH avatar Dec 17 '24 17:12 RichRH

yes it seems to happen when we select bigger resolutions for multiple recording streams. we will give moreinfo this weekend.

richard12121212 avatar Dec 18 '24 20:12 richard12121212

Leak is still happening. 360 Capture on Windows Builds with 8Kx4K resolution. Even on 128 GB you will run out at approximately 1gb/sec. DX12 OR 11.

thePostFuturist avatar Mar 17 '25 01:03 thePostFuturist

Hi @thePostFuturist,

Thanks for the update - are you able to confirm which Unity and which AVPro Movie Capture version(s) you're using to exhibit this?

Cheers,

RichRH avatar Mar 17 '25 14:03 RichRH

Any more info @thePostFuturist ?

Chris-RH avatar Mar 24 '25 10:03 Chris-RH

unity 6.000.0.23f1 latest version of avpmvc

On Mon, Mar 24, 2025, 03:37 Chris-RH @.***> wrote:

Any more info @thePostFuturist https://github.com/thePostFuturist ?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGNS4QSJSSA55NDPLMPON32V7N5NAVCNFSM6AAAAABJCSLLI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBXGY2TKOBSGA . You are receiving this because you were mentioned.Message ID: @.*** com> [image: Chris-RH]Chris-RH left a comment (RenderHeads/UnityPlugin-AVProMovieCapture#401) https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820

Any more info @thePostFuturist https://github.com/thePostFuturist ?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGNS4QSJSSA55NDPLMPON32V7N5NAVCNFSM6AAAAABJCSLLI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBXGY2TKOBSGA . You are receiving this because you were mentioned.Message ID: @.*** com>

thePostFuturist avatar Mar 24 '25 20:03 thePostFuturist

If ANY part of recording could be processed on a 2nd video card, this would be a game changer. Otherwise 8kx4k 360 captures are capped at 15 fps or so even on a scene that can run easily on a phone

On Mon, Mar 24, 2025, 13:08 Valentin Burov @.***> wrote:

unity 6.000.0.23f1 latest version of avpmvc

On Mon, Mar 24, 2025, 03:37 Chris-RH @.***> wrote:

Any more info @thePostFuturist https://github.com/thePostFuturist ?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGNS4QSJSSA55NDPLMPON32V7N5NAVCNFSM6AAAAABJCSLLI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBXGY2TKOBSGA . You are receiving this because you were mentioned.Message ID: @.*** com> [image: Chris-RH]Chris-RH left a comment (RenderHeads/UnityPlugin-AVProMovieCapture#401) https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820

Any more info @thePostFuturist https://github.com/thePostFuturist ?

— Reply to this email directly, view it on GitHub https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/401#issuecomment-2747655820, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGNS4QSJSSA55NDPLMPON32V7N5NAVCNFSM6AAAAABJCSLLI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONBXGY2TKOBSGA . You are receiving this because you were mentioned.Message ID: @.*** com>

thePostFuturist avatar Mar 24 '25 20:03 thePostFuturist

Hi @thePostFuturist, After looking into this it seems to be intended behaviour of MediaFoundation as it will internally buffer frames if the data throughput is too high this will eventually lead to the system running out of memory. The next version will include a workaround that will keep track of the internal buffer and stop pushing frames to it if it gets overloaded. However, I would highly recommned using "Offline Capture" which in our testing does not result in such an issue. As for your comments on the speed of the capture, this is not a limitation of the complexity of the scene but the hardware being used, the encoding process is very intensive for captures of this size, especially when doing 360 captures.

Reuben-RH avatar Apr 02 '25 10:04 Reuben-RH

Hello, we also encountered a similar issue with memory usage increasing during video export in [Version](version: 5.3.3 (plugin v5.3.3f1-ultra))

liuwjchinal avatar May 30 '25 03:05 liuwjchinal

Unity Version 2022.3.16f1

AVPro Movie Capture Version 5.3.3

Which platform(s) are you using? Windows

Which OS version(s) are you using? Windows 10

Which rendering API(s) are you using? Direct3D 11

Hardware Processor: Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz Installed RAM: 32.0 GB (31.7 GB usable) System type: 64-bit operating system, x64-based processor GPU: NVIDIA GeForce GTX 1080

Which capture component are you using? Capture From Texture

Capture mode Realtime

Which output mode are you using? Video file

Video codecs H264

Audio source Unity

Audio codecs AAC

Any other component configuration Frame Rate: 30 Source Texture: camera.targetTexture Camera Render Resolution: HD_1920x1080 Output Target: Video File

liuwjchinal avatar May 30 '25 03:05 liuwjchinal

@RichRH @Chris-RH @MorrisRH Looking forward to your prompt response. Thank you. Best regards.

liuwjchinal avatar May 30 '25 03:05 liuwjchinal

Image

liuwjchinal avatar May 30 '25 03:05 liuwjchinal

Please wait until after the next release to see if the issue still occurs

Chris-RH avatar May 30 '25 11:05 Chris-RH

When will the next version be released?

liuwjchinal avatar Jun 03 '25 02:06 liuwjchinal

Could you release a fix patch for version 5.3.3, or share the PDB symbol files for the corresponding 5.3.3 DLL with us? We would like to see how we can implement a workaround from the upper layer.

liuwjchinal avatar Jun 03 '25 02:06 liuwjchinal

AVPro Movie Capture version 5.3.4 has been released. Please let us know if your issue has not been fixed.

Chris-RH avatar Jun 07 '25 11:06 Chris-RH

Hello, thank you for your prompt response. We have now upgraded to the latest version 5.3.4. Based on our current testing, the previous issue has not reoccurred. It seems that the new version has resolved our problem very well. Thank you again!

liuwjchinal avatar Jun 10 '25 03:06 liuwjchinal