cefsharp / CefSharp.Wpf.HwndHost

Designed as a drop in replacement for CefSharp.Wpf for those who want the native Win32 based implementation (For IME support and better performance).
Other
34 stars 10 forks source link

ILifeSpanHandler may have been set to null when ClientAdapter::DoClose is called. #10

Closed kkwpsv closed 3 years ago

kkwpsv commented 3 years ago

When closing a ChromiumWebBrowser, ClientAdapter::DoClose is called at 'CrBrowserMain' thread and ILifeSpanHandler is set to null at main thread. ILifeSpanHandler.DoClose may not be called because ILifeSpanHandler has been set to null. This may lead to that the parent window of ChromiumWebBrowser will be closed. When ChromiumWebBrowser is visible, this has no special effect. Beacuse it doesn't have parent now. When ChromiumWebBrowser is not visible, it has been reparented to SystemResourceNotifyWindow by HwndHost. And all hidden HwndHost is reparented to is. This will cause all hidden HwndHost is closed.

amaitland commented 3 years ago

Pull requests welcome.

amaitland commented 3 years ago

For now we'll just leave the GC to take care of the LifeSpanHandler property, it's unlikely this will cause any leaks.

It sounds like the reference to ChromiumWebBrowser in ClientAdapter::DoClose is still valid, no report of exception, so hopefully this resolves the problem.

If the problem still occurs I'll leave you to debug further.

kkwpsv commented 3 years ago

Sorry for no reply for so long.

I have debugged this. And found two solution:

But neither of these two methods directly solve the thread timing issues. So i didn't make a pull request at that time and make this issue to know if there is a more direct solution.

Setting LifeSpanHandler to null should not cause any leaks. And I have checked the reference to ChromiumWebBrowser is still valid. And i think this solution is also acceptable.

amaitland commented 3 years ago

Thanks for the feedback 👍

Change is included in https://www.nuget.org/packages/CefSharp.Wpf.HwndHost/89.0.170