smourier / VCamSample

Windows 11 Virtual Camera sample code.
MIT License
32 stars 7 forks source link

Frame server process rarely crash when running both VCamSample and another web camera. #4

Closed HexagramNM closed 2 weeks ago

HexagramNM commented 4 months ago

Thank you for publishing your sample on virtual camera using media foundation api. This is very helpful for me!

I find a rare crash bug around the virtual camera.

How to reproduce

  1. Open windows camera application, and show a video from another web camera.

  2. Start VCamSample.

  3. Use its virtual camera in application. I use Discord.

  4. Randomly, frame server crashes, and a video from the virtual camera stops. (Sometimes, it took several tens of minutes to reproduce the crash...)

When I run only VCamSample and don't use another web camera, I don't find the crash.

Error report from Reliability monitor

スクリーンショット 2024-07-18 222412

But I found other errors with different exception codes (c0000374, c0000005) and fault modules (StackHash, VCamSampleSource.dll.)

Machine spec where the crash occurs

OS: Windows 11 Home (23H2) CPU: 13th Gen Intel(R) Core(TM) i7-13700H 2.40 GHz RAM: 32GB GPU: NVIDIA GeForce RTX 4060 Laptop GPU

I think it can be a bug of Windows frame server, but do you know any information or limitation?

smourier commented 4 months ago

What do you mean by "another web camera"? I can't easily reproduce this, so it's difficult to determine from where it's coming.

HexagramNM commented 4 months ago

My machine (laptop) has an embeded web camera, and I meant it. The crash seems to occur when both the web camera and the virtual camera is running.

smourier commented 4 months ago

I have no idea where the problem can come from. I've been running a camera, discord (or other), vcamsample etc for a long time and it don't see any problem.

HexagramNM commented 4 months ago

Thank you for your trying. In that case, it may be a problem of my environment...

Once, I close this issue. If I have any update, I'll let you know.

HexagramNM commented 2 weeks ago

Hi. I investigated the problem and I found one of the cause. So, I reopen this issue.

In FremeGenerator.cpp, you called lock->Release(). https://github.com/smourier/VCamSample/blob/f006d573edebe7c4b8f0d8a79299438205e77224/VCamSampleSource/FrameGenerator.cpp#L289

com_ptr_nothrow<IWICBitmapLock>, which is the type of lock, calls Release method in its destructor, too. Therefore, Release method for lock is called twice, and it sometimes causes crash. To delete lock object explicitly, you should use lock.reset() instead.

I think this fix also solves my problem.

smourier commented 2 weeks ago

Indeed, I'm juggling with all kinds of smart pointers with different semantics in my projects... This was changed in this commit https://github.com/smourier/VCamSample/commit/62654a648186b02a557a059c01f8a229c0a333e7

HexagramNM commented 2 weeks ago

This was changed in this commit https://github.com/smourier/VCamSample/commit/62654a648186b02a557a059c01f8a229c0a333e7

Great! Thank you for the commit. I'll close this issue.