OnBeforePopup scoped_refptr access violation

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.

OnBeforePopup scoped_refptr access violation

Postby czaarek99 » Wed Apr 25, 2018 10:01 am

I recently upgraded from 12/01/2017 - CEF 3.3202.1690.gcd6b88f / Chromium 62.0.3202.94 to ---> 04/19/2018 - CEF 3.3359.1768.g8e7c5d6 / Chromium 66.0.3359.117 because of a bug in AudioContext which prevented replay of some mp3s. For some strange reason my code now has a very strange bug which I really don't understand. Every single time when CEF starts I get an access violation in OnBeforePopup.

Here is the stack trace:
Code: Select all
    Shadow.exe!scoped_refptr<CefFrame>::~scoped_refptr<CefFrame>() Line 323   C++   Symbols loaded.
>   Shadow.exe!CefLifeSpanHandler::OnBeforePopup(scoped_refptr<CefBrowser> browser, scoped_refptr<CefFrame> frame, const CefStringBase<CefStringTraitsUTF16> & target_url, const CefStringBase<CefStringTraitsUTF16> & target_frame_name, cef_window_open_disposition_t target_disposition, bool user_gesture, const CefStructBase<CefPopupFeaturesTraits> & popupFeatures, CefWindowInfo & windowInfo, scoped_refptr<CefClient> & client, CefStructBase<CefBrowserSettingsTraits> & settings, bool * no_javascript_access) Line 90   C++   Symbols loaded.
    Shadow.exe!`anonymous namespace'::load_handler_on_loading_state_change(_cef_load_handler_t * self, _cef_browser_t * browser, int isLoading, int canGoBack, int canGoForward) Line 40   C++   Symbols loaded.
    libcef.dll!CefLoadHandlerCToCpp::OnLoadingStateChange(scoped_refptr<CefBrowser>) Line 37   C++   Symbols loaded.
    libcef.dll!CefBrowserHostImpl::LoadingStateChanged(content::WebContents * source, bool to_different_document) Line 2218   C++   Symbols loaded.
    libcef.dll!content::WebContentsImpl::LoadingStateChanged(bool to_different_document, bool due_to_interstitial, content::LoadNotificationDetails * details) Line 4522   C++   Symbols loaded.
    libcef.dll!content::WebContentsImpl::DidStartLoading(content::FrameTreeNode * frame_tree_node, bool) Line 5087   C++   Symbols loaded.
    libcef.dll!content::FrameTreeNode::DidStartLoading(bool to_different_document, bool was_previously_loading) Line 558   C++   Symbols loaded.
    libcef.dll!content::FrameTreeNode::CreatedNavigationRequest(std::unique_ptr<content::NavigationRequest,std::default_delete<content::NavigationRequest> > navigation_request) Line 498   C++   Symbols loaded.
    libcef.dll!content::NavigatorImpl::RequestNavigation(content::FrameTreeNode * frame_tree_node, const GURL & navigation_start, const content::Referrer &) Line 1071   C++   Symbols loaded.
    libcef.dll!content::NavigatorImpl::NavigateToEntry(content::FrameTreeNode * frame_tree_node, const content::FrameNavigationEntry &) Line 338   C++   Symbols loaded.
    libcef.dll!content::NavigatorImpl::NavigateToPendingEntry(content::FrameTreeNode * frame_entry, const content::FrameNavigationEntry & reload_type, content::ReloadType is_same_document_history_load, bool navigation_ui_data, std::unique_ptr<content::NavigationUIData,std::default_delete<content::NavigationUIData> >) Line 387   C++   Symbols loaded.
    libcef.dll!content::NavigationControllerImpl::NavigateToPendingEntryInternal(content::ReloadType reload_type, std::unique_ptr<content::NavigationUIData,std::default_delete<content::NavigationUIData> >) Line 2157   C++   Symbols loaded.
    libcef.dll!content::NavigationControllerImpl::NavigateToPendingEntry(content::ReloadType reload_type, std::unique_ptr<content::NavigationUIData,std::default_delete<content::NavigationUIData> >) Line 2111   C++   Symbols loaded.
    libcef.dll!content::NavigationControllerImpl::LoadEntry(std::unique_ptr<content::NavigationEntryImpl,std::default_delete<content::NavigationEntryImpl> > navigation_ui_data, std::unique_ptr<content::NavigationUIData,std::default_delete<content::NavigationUIData> >) Line 512   C++   Symbols loaded.
    libcef.dll!content::NavigationControllerImpl::LoadURLWithParams(const content::NavigationController::LoadURLParams & params) Line 870   C++   Symbols loaded.
    libcef.dll!content::NavigationControllerImpl::LoadURL(const GURL & url, const content::Referrer & referrer, ui::PageTransition transition, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & extra_headers) Line 722   C++   Symbols loaded.
    libcef.dll!CefBrowserHostImpl::LoadURL(__int64 frame_id, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & url, const content::Referrer & referrer, ui::PageTransition transition, const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & extra_headers) Line 1670   C++   Symbols loaded.
    libcef.dll!CefBrowserHostImpl::Create(CefBrowserHostImpl::CreateParams & create_params) Line 372   C++   Symbols loaded.
    libcef.dll!CefBrowserHost::CreateBrowserSync(const CefWindowInfo & client, scoped_refptr<CefClient>) Line 274   C++   Symbols loaded.
    libcef.dll!`anonymous namespace'::CreateBrowserWithHelper(`anonymous namespace'::CreateBrowserHelper * helper) Line 142   C++   Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::FunctorTraits<void (*)(blink::WaitableEvent *),void>::Invoke(void(*)(blink::WaitableEvent *)) Line 402   C++   Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::InvokeHelper<0,void>::MakeItSo(void(*)(blink::WaitableEvent *) &) Line 530   C++   Symbols loaded.
    [Inline Frame] libcef.dll!base::internal::Invoker<base::internal::BindState<void (*)(blink::WaitableEvent *),WTF::CrossThreadUnretainedWrapper<blink::WaitableEvent> >,void ()>::RunImpl(void(*)(blink::WaitableEvent *) & bound, const std::tuple<WTF::CrossThreadUnretainedWrapper<blink::WaitableEvent> > &) Line 604   C++   Symbols loaded.
    libcef.dll!base::internal::Invoker<base::internal::BindState<void (*)(blink::WaitableEvent *),WTF::CrossThreadUnretainedWrapper<blink::WaitableEvent> >,void ()>::Run(base::internal::BindStateBase * base) Line 586   C++   Symbols loaded.
    [Inline Frame] libcef.dll!base::OnceCallback<void ()>::Run() Line 95   C++   Symbols loaded.
    libcef.dll!base::debug::TaskAnnotator::RunTask(const char * queue_function, base::PendingTask * pending_task) Line 61   C++   Symbols loaded.
    libcef.dll!base::internal::IncomingTaskQueue::RunTask(base::PendingTask * pending_task) Line 124   C++   Symbols loaded.
    libcef.dll!base::MessageLoop::RunTask(base::PendingTask * pending_task) Line 396   C++   Symbols loaded.
    libcef.dll!base::MessageLoop::DeferOrRunPendingTask(base::PendingTask pending_task) Line 407   C++   Symbols loaded.
    libcef.dll!base::MessageLoop::DoWork() Line 451   C++   Symbols loaded.
    libcef.dll!base::MessagePumpForUI::DoRunLoop() Line 174   C++   Symbols loaded.
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate) Line 58   C++   Symbols loaded.
    libcef.dll!base::MessageLoop::Run(bool application_tasks_allowed) Line 348   C++   Symbols loaded.
    libcef.dll!base::RunLoop::Run() Line 136   C++   Symbols loaded.
    libcef.dll!CefBrowserMessageLoop::RunMessageLoop() Line 122   C++   Symbols loaded.
    libcef.dll!CefRunMessageLoop() Line 290   C++   Symbols loaded.
    Shadow.exe!CefRunMessageLoop() Line 407   C++   Symbols loaded.
    Shadow.exe!wWinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, wchar_t * lpCmdLine, int nCmdShow) Line 22   C++   Symbols loaded.
    [External Code]      Annotated Frame


When the code enters OnBeforePopup most of the information is pure garbage:
Image

So later when the scoped_refptr for those is freed it throws an access violation:
Image

I'm attaching a minimal example which leads to the crash. There is a lot that this example lacks like shutting down properly and so on. I removed those to make it easier to understand. But the issue is that CEF won't even start with this code.

But there is a way to fix this and make this minimal example start properly. Open up the BrowserEventHandler.h file

Code: Select all
#pragma once

#include "stdafx.h"

#include "cef_client.h"
#include "wrapper/cef_message_router.h"

class BrowserEventHandler :
   public CefClient,
   public CefLifeSpanHandler {
public:

   CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
      return this;
   }

private:
IMPLEMENT_REFCOUNTING(BrowserEventHandler);
};


If you simply change return this to return NULL like this:
Code: Select all
#pragma once

#include "stdafx.h"

#include "cef_client.h"
#include "wrapper/cef_message_router.h"

class BrowserEventHandler :
   public CefClient,
   public CefLifeSpanHandler {
public:

   CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override {
      return NULL;
   }

private:
IMPLEMENT_REFCOUNTING(BrowserEventHandler);
};


Everything works fine.

I tried this with my full project too. If I just remove the LifeSpanHandler it stops crashing. But this is obviously not an option as I have to handle shutdown and so on somehow in my application.

I'd appreciate some help here :)
Attachments
minimal ex.zip
Minimal example of code that crashes
(6.38 KiB) Downloaded 406 times
czaarek99
Newbie
 
Posts: 4
Joined: Wed Apr 25, 2018 9:47 am

Re: OnBeforePopup scoped_refptr access violation

Postby magreenblatt » Wed Apr 25, 2018 10:07 am

What OS? Does the crash reproduce with the CEF sample applications? If not, how does your code differ from those applications?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforePopup scoped_refptr access violation

Postby ndesktop » Wed Apr 25, 2018 10:19 am

What does your CefLifeSpanHandler implementation looks like? Or there is none, you just say "I implement CefLifeSpanHandler: via GetLifeSpanHandler and that's it?
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: OnBeforePopup scoped_refptr access violation

Postby czaarek99 » Wed Apr 25, 2018 10:28 am

ndesktop wrote:What does your CefLifeSpanHandler implementation looks like? Or there is none, you just say "I implement CefLifeSpanHandler: via GetLifeSpanHandler and that's it?

I attached a minimal code sample. I am using the default implementation. I just extend CefLifeSpanHandler in my CefClient implementation. I don't override any methods. The default function throws.
magreenblatt wrote:What OS? Does the crash reproduce with the CEF sample applications? If not, how does your code differ from those applications?

This is on Windows 10. The samples don't crash.

Answering how they differ is kind of impossible. The minimal example that I attached is a very stripped down version of my real project. I just removed everything that I could while making the sample work with that single point of failure. If you return NULL in GetLifeSpanHandler everything works fine. Otherwise it crashes.

If you just look at the very small code sample I provided you'll see. It's really small.
czaarek99
Newbie
 
Posts: 4
Joined: Wed Apr 25, 2018 9:47 am

Re: OnBeforePopup scoped_refptr access violation

Postby czaarek99 » Fri Apr 27, 2018 2:43 am

I did some more research into this. Cefsimple works just fine if I use the binaries that are given to me prebuilt. But if I build the cefsimple myself with Visual Studio I get the same issue.
czaarek99
Newbie
 
Posts: 4
Joined: Wed Apr 25, 2018 9:47 am

Re: OnBeforePopup scoped_refptr access violation

Postby magreenblatt » Fri Apr 27, 2018 2:55 am

Are you using the provided cmake files to generate the VS project files? Have you changed anything in the configuration?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: OnBeforePopup scoped_refptr access violation

Postby czaarek99 » Sat Apr 28, 2018 12:37 pm

magreenblatt wrote:Are you using the provided cmake files to generate the VS project files? Have you changed anything in the configuration?


If I build it using the generated .sln file from Cmake then cefsimple works just fine. But the same code doesn't work when I build it using my own visual studio configuration. That configuration worked just fine with Chrome 57.

So obviously something is wrong in my own configuration. What I don't understand is how I'm supposed to know what settings my project should have to not compile into a mess. Is there some kind of guide how to make your own project and how to make it build?
czaarek99
Newbie
 
Posts: 4
Joined: Wed Apr 25, 2018 9:47 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 16 guests