RenderHeads / UnityPlugin-AVProMovieCapture

AVPro Movie Capture is a Unity Plugin for advanced video capture to AVI/MP4/MOV files
https://renderheads.com/products/avpro-movie-capture/
43 stars 8 forks source link

[Bug] Memory leak occurs when using OpenGLES3 in Demo01-TextureCapture On Android #364

Closed LightGather closed 4 months ago

LightGather commented 5 months ago

Unity Version

2021.3.28f1

AVPro Movie Capture Version

5.2.0-Ultra Edition

Which platform(s) are you using?

Android

Which OS version(s) are you using?

Android 13

Which rendering API(s) are you using?

OpenGLES

Hardware

Samsung Galaxy Note 20 Ultra, Galaxy A23, Galaxy Note 8

Which capture component are you using?

Capture From Texture

Capture mode

Offline

Which output mode are you using?

Video file

Video codecs

H264

Audio source

None

Audio codecs

AAC

Any other component configuration

Change graphics API in Unity rendering settings from auto to OpenGLES3. Use URP.

The issue

As described in the configuration item, after changing the graphics API to OpenGLES3, I built the TextureCapture demo and ran it on an Android device. However, when capturing and stopping are repeated, the total memory used by the app continues to increase by about 20 to 30 megabytes. This is very easy to reproduce.

The same problem occurs not on one device but on multiple Android phones. This problem does not appear when using auto or Vulkan as the Graphics API. The reason I use OpenGLES3 is because I use AVProVideo, and AVProVideo only supports OpenGLES on Android. This problem appears if the graphics API is OpenGLES3, whether you use AVProVideo or not.

I have been using AVProVideo since purchasing it a long time ago, and I recently purchased AVProMovieCapture Ultra version for immediate use. Please resolve this issue quickly.

Log output

No response

LightGather commented 5 months ago

Can you please let me know if this issue is being resolved? Because this is a very important issue for our application.

Chris-RH commented 5 months ago

Have you tried it in SRP and does this still occur? Does this keep increasing or does it tail off after a while? How long are you running it for? If you leave it running, will the memory keep increasing until it crashes? Have you tried garbage collection ? How are you measuring the memory leak?

We are planning on supporting Vulkan when we release AVPro Video version 3.

LightGather commented 5 months ago

Have you tried it in SRP and does this still occur? I haven't tried it with srp, because I'm trying to use AVMovieCapture on an app I've already released, and I'm using URP there, so I must use this on URP.

Does this keep increasing or does it tail off after a while? How long are you running it for? If you leave it running, will the memory keep increasing until it crashes? The memory doesn't decrease over time, it keeps increasing. As I explained above, every time I repeat start capture, stop capture increases by 20~30Mb. It keeps increasing no matter how many times I repeat it, so it increases to 1GB or more. (This didn't happen at all when I used Vulkan.)

Have you tried garbage collection ? How are you measuring the memory leak? I've done memory checks using the adb shell command, and I've used Unity Profiler, Android Profiler. And they've all checked the memory leaks. Since this memory is allocated on the native side of the AVMovieCapture plug-in, calling Unity GC won't solve the problem.

I've reported to you a memory-rick issue that appears in 360 encoding of an earlier version of AVMovieCapture that only supported iOS, and you guys managed to resolve the issue thankfully quickly. Here's a link to the issue back then. https://github.com/RenderHeads/UnityPlugin-AVProMovieCapture/issues/164 I think if you set up and check to use the same environment as me, URP and GLES3, you can easily reproduce the problem and identify the cause. Please reproduce and solve the problem. I love this plug-in very much, but I cannot not using it on Android just because of this problem. AVProVideo I love it and I'm using it well. It's very positive that you have a plan to support Vulkan. But since my project is already use GLES3, this issue needs to be solved in GLES first. Thank you for developing such a good plug-in, and please help me.

FloraJungeunLee commented 5 months ago

I have the same problem too. I hope it gets resolved soon. It's also an urgent issue in our app.

Chris-RH commented 5 months ago

What shader are you using? Have you tried Unity 2022? The memory profiler is more in depth and might give more accurate information

LightGather commented 5 months ago

2022 is not the version I use. As I said, I'm using this in a commercial project and I can't change the version. I tested it using demo01 that you made. Of course, the shader used what you put in demo01. Have you checked for memory leaks in the environment I mentioned?

LightGather commented 5 months ago

Once again, you can reproduce it by just building the demo you made with Unity version 2021.3.28f1 and gles3 and uploading it to an Android device. I want you to try reproducing this. If I were to change and use yours, I would naturally check to see if there were any problems with my code. However, I just built and ran the demo you made, and that issue was found, and the adb shell command can most accurately check the app's memory. I have been working in this field for a long time and the memory checking method I used is correct. Please, please, build your demo, upload it to Android, and check it out.

Chris-RH commented 5 months ago

@FloraJungeunLee A bit more info please

Can you send us a simple reproducible project to unitysupport@renderheads.com

LightGather commented 5 months ago

@Chris-RH Have you checked the memory while using gles3 in demo01? Can't you reproduce the problem with the same setup?

MorrisRH commented 4 months ago

Reproduced. Nothing URP specific about it. Seems something changed and Unity's GL context is no longer current when shutdown is being called. A fix will make it into the next release.

LightGather commented 4 months ago

@MorrisRH I'm so glad you solved the problem. I will test it as soon as the next release is updated.

LightGather commented 4 months ago

@MorrisRH Can you tell me the next release schedule? I'm asking you because I really want to be able to use this plugin, but cannot use this unless the fix is ​​updated. This is a very important issue in our app's development schedule.

MorrisRH commented 4 months ago

The next release is currently in testing and we hope to get it released before the end of the week.

LightGather commented 4 months ago

That's good news. Thank you for the reply.

Chris-RH commented 4 months ago

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

LightGather commented 4 months ago

After updating to 5.2.1, the problem seems to have been resolved. thank you! And I have one question. I'm looking for a way to handle errors when an error occurs during the capturning process in Android. Isn't the SetErrorHandler function available in Android?

Chris-RH commented 4 months ago

hmm, yes SetErrorHandler is actually legacy and no longer does anything. Most of the time when errors occur, its during reorder creation, which is flagged as you don't get a recorder. The issue is that when it fails during recording, you don't really get much info when things do go wrong. Its often very specific, so its difficult to come up with a solution for handling errors.