hecomi / uWindowCapture

This allows you to use Windows Graphics Capture / PrintWindow / BitBlt in Windows to capture multiple windows individually and easily use them as Texture2D in Unity.
https://tips.hecomi.com/entry/2021/04/30/230322
MIT License
505 stars 81 forks source link

Windows Crash from CaptureService.dll eating up pagefile #47

Open timwillhack opened 2 years ago

timwillhack commented 2 years ago

I have a beefy computer, 64GB ram, 3090 24gb, 3950x. I have a pagefile of 160gb that fills up if I leave a unity build with uWindowCapture running overnight. The strange thing, if I watch it during the day in the editor, it doesn't seem to be eating up the pagefile, but I mostly go in and out of play mode during the day. Today was the first time I was able to verify that the pagefile was linked to the unity project build as when windows crashed, it just killed the capture but the unity app stayed running, I had meminfo up with the whole pagefile filled, and it didn't empty down to 22gb until I killed the unity built app. Its using the windows game capture methodology.

hecomi commented 2 years ago

Thank you for your report.

It seems to be related to some bug, but I cannot reproduce it at hand..., so if you find any specific way to reproduce it, that would be helpful in my investigation.

timwillhack commented 2 years ago

BTW, my unity version is 2021.3.6f1 LTS. I believe I was having the same issue with this running in my previous unity version which was 2019.X something or other, so most likely it at least isn't a bug related to the version of unity.

The only way I've been able to get it to happen is if I leave it capturing overnight, pretty much every morning after, my computer crashed at night. Maybe try turning it on and letting it run overnight on your comp (but do it on a computer you are ok enough with crashing PLEASE)

The last time mine crashed it was so bad that I had to do a system restore my boot disk afterward about a week ago. It basically maxed out the page file, causing a crash that left any files open on my ssd to end up with corrupt data after. Luckily I'm a bit crazy about my backups and it restored to the previous nights backup fine, but I lost a day having it restore a 1tb boot disk unfortunately.

I was considering recording a video of task manager etc running at night to see the buildup but I don't think it would capture enough information to warrant doing unless we could figure out how to monitor something close enough to see.

I've temporarily added a bandaid to track if the capturer is capturing an idle app (using getpixels and basically monitoring for a paused like state) and turning off the game object in that case, and have a button to turn it back on. So far I haven't had a crash at night since I've done this but this will mean I'll have to keep killing the app and reopening it so that it doesn't build up to the crash state. This is doable for my use case but other people it probably won't be possible. I haven't gotten to a point that I've really looked at the plugin source myself but figured its probably in there somewhere, maybe some sort of memory leak with the textures.

As a side, I use OBS to do game capture for other things and I believe its capture mechanism is using the same windows game capture service of windows and I can have that running for a really really long time without crashes, so I don't think its related to a buggy windows game capture service itself.

I'll continue to try to figure out how to reproduce, and at a minimum try to see it building up the pagefile size.

Thank you for trying to figure it out and thank you for making this plugin, its been great other than this!