jacobbo / WebEye

WebEye is a collection of .NET controls.
190 stars 132 forks source link

Crash upon closing application #18

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hello,

When I'm using WebEye, I have put the control in a couple of WPF pages that you can navigate to on demand. However, I have an issue where if I open a page with the WebEye control, leave the page which should unload that previous page completly and then navigate back to the page with the WebEye control and then I close the application I get the following error that is not trappable and is thrown inside of Visual Studio...

Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'C:\Users\xxxx\Documents\Visual Studio 2015\Projects\Cube\Launcher\bin\Debug\Launcher.vshost.exe'.

Additional information: Transition into COM context 0x8b4018 for this RuntimeCallableWrapper failed with the following error: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). This is typically because the COM context 0x8b4018 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

I've tried attaching the source code but I cannot identify the location of the issue as I'm not terribly experienced connecting to COM like you are. It feels like an object was created but not cleaned up in the appropriate time.

I hope that you're still reviewing issues and might be able to shed some light on to why this issue is occurring so that I may correct it.

Thank you, Michael

jacobbo commented 7 years ago

Hi there, the control requires a window (specifically, a HWND) to output the video steam and if the window has been destroyed (like in your case, I believe), then you have to recreate the control, otherwise you will get an exception.

Regards, Alexander

ghost commented 7 years ago

Hello Alexander,

I think I understand what you're saying, however this is upon exiting the application... there is no exception until I close my application. Creating and destroying the pages do not cause any issues (perhaps a memory leak but I haven't checked that yet).

Are you saying that I, for some reason, need to have the page with WebEye available and in memory upon exiting the application to not get this exception? That would be very strange to me, and I would like a way to invoke the close/release memory/or whatever to manually do that before I exit the application.

These would be the steps I'm doing:

  1. Start application and navigate to the main page that does not have WebEye. (Creates main page)
  2. Navigate to page with WebEye. (Unloads the main page and creates page with WebEye)
  3. Navigate to main page without WebEye. (Unloads previous page and creates main page)
  4. Navigate to page with WebEye. (Unloads main page and creates page with WebEye).
  5. Close the application .
  6. As the application is closing the system will generate the previously mentioned exception. However it's only visible in Visual Studio, if I run the Exe stand alone I don't 'see' the exception, however it's still there.

If I do other steps, such as only going to the page with WebEye once or not even opening WebEye the first time, I don't get the exception. I've tested the code and the unload events are firing and I tried forcing garbage collection, neither helped the situation.

Any ideas based on this new information?

Thank you, Michael

jacobbo commented 7 years ago

Hi Michael,

Do you have a minimal VS project which reproduces the exception?

Regards, Alexander

ghost commented 7 years ago

Hello Alexander,

Here is a stripped down version that causes the exception: WebEyeIssue.zip

Steps to reproduce:

  1. Start the WebEyeIssue application.
  2. Press the "CLICK ME" button in the middle of the screen.
  3. It will take you to a screen that automatically starts the WebEye control. On that page there is a button on the bottom of the screen that says "CLICK ME"... click it.
  4. It takes you back to the original screen, press the "CLICK ME" button in the middle of the screen.
  5. It will take you to the screen that has the WebEye control running again.
  6. Press the X to close the application.
  7. It should now crash inside the Visual Studio application with the following error:

Managed Debugging Assistant 'DisconnectedContext' has detected a problem in 'C:\Users\xxx\Documents\Visual Studio 2015\Projects\WebEyeIssue\bin\Debug\Launcher.vshost.exe'.

Additional information: Transition into COM context 0x12e5f50 for this RuntimeCallableWrapper failed with the following error: The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED)). This is typically because the COM context 0x12e5f50 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

I'm using Visual Studio 2015 with the latest updates, if that makes any difference.

Thank you, Michael

jacobbo commented 7 years ago

Hi Michael,

I see the issue and have a fix for it, just give me a day.

Regards, Alexander

jacobbo commented 7 years ago

Remove a reference to the WebEye.Controls.Wpf.WebCameraControl.dll file and add the following nuget package to your solution instead, it should fix the issue. https://www.nuget.org/packages/WebEye.Controls.Wpf.WebCameraControl/

ghost commented 7 years ago

Thank you for all your hard work Alexander, it's no longer crashing! :)