OnQuery return value "side effect"

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

OnQuery return value "side effect"

Postby BaroneAshura » Thu May 17, 2018 4:48 am

Hello,

I went on with the development and integration of our c++/MFC application and stumbled upon a side effect which is verylikely determined by my ignorance about the whole CEF framework.

The application opens a browser on a local file HTML file, which needs to execute javascript. In order to achieve communication between JS and the MFC application I decided to take the path of the MessageRouter.
Everything works fine, communication between JS and C++ works fine, and everything is being performed as expected.

The "side effect", is that when I called CefShutdown, I end up failing the following DCHECK:
[0517/113444.995:FATAL:libcef_dll_wrapper.cc(242)] Check failed: base::AtomicRefCountIsZero(&CefBrowserCToCpp::DebugObjCt).


I spent lots of time on this post about the failed DCHECK: http://magpcss.org/ceforum/viewtopic.php?f=6&t=13556, and I made sure that everything as being executed at shutdown as suggested there.
I spent lots of time in trying to understand which/where/when I was copying around my CefRefPtr<CefBrowser> handle, but couldnt find it. Then yesterday I tried to locate the 'offending' part of code, whether it was some Handler method, or the html code, or the JS code or the communication between JS and MFC. The I finally identified where the 'offending' line of code was... It is the return value of the OnQuery callback implemented in my class inheriting from CefMessageRouterBrowserSide. Below there is the trimmed down implementation that allowed me to pinpoint the issue.

Code: Select all
class MessageHandler : public CefMessageRouterBrowserSide::Handler {
public:
    explicit MessageHandler(const CefString& startup_url)
        : startup_url_(startup_url) {}

    // Called due to cefQuery execution in message_router.html.
    bool OnQuery(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        int64,
        const CefString& request,
        bool,
        CefRefPtr<Callback> callback) OVERRIDE
    {
 
        return true;
    }
}


If I return true, then I have a leftover instance of CefBrowser... if I return false, then everything is being cleaned up appropriately and CefShutdown completes without issues.

I am very well aware that there are still too many things I dont have complete understanding of, so I would really appreciate if someone could help me in understanding a little bit more about this 'scenario'.
I am pretty sure that I did something wrong somewhere, or that we are missing some parts somewhere else, or both -.-

We are using Visual Studio 2017 15.7.0, and now we are integrating version 3.3359.1772

If you need further information, I will provide them

Thanks in advance
BaroneAshura
Newbie
 
Posts: 6
Joined: Thu Apr 26, 2018 2:52 am

Re: OnQuery return value "side effect"

Postby magreenblatt » Thu May 17, 2018 1:51 pm

Are you calling all of the CefMessageRouter methods from the correct callbacks? See the example at https://bitbucket.org/chromiumembedded/ ... ?at=master
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: OnQuery return value "side effect"

Postby BaroneAshura » Fri May 18, 2018 5:33 am

Again thanks!

I did call and implement the right callbacks related to CefMessageRouters, but I went again through the example... I am slowly understanding small parts of CEF everyday.

I turns out that I had a simplified and messed up application initialization sequence, as well a simplified and messed up application shutdown sequence.
I hope I finally got a solid grasp of the CEF processes initialization.

Currently refactoring the whole thing, then I'll give check again the aftermath or returning true from the OnQuery callback.
BaroneAshura
Newbie
 
Posts: 6
Joined: Thu Apr 26, 2018 2:52 am

Re: OnQuery return value "side effect"

Postby BaroneAshura » Fri May 18, 2018 8:31 am

Got IT ! :)

I had forgot to call RemoveHandler in OnBeforeClose callback

thanks again
BaroneAshura
Newbie
 
Posts: 6
Joined: Thu Apr 26, 2018 2:52 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 62 guests