Crash: Check failed: CefCurrentlyOn(TID_UI)

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.

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby pascalkhoury » Tue Feb 14, 2023 7:32 am

BorjaPascual wrote:
Yeah, it seems to be CefInitialize. Here's the code, which I copypasted fromm cefsimple:

Code: Select all
CefRefPtr<CefApp> app(new CCefSimpleApp(std::string(url.GetBuffer())));
  int exit_code = CefExecuteProcess(main_args, app, sandbox_info);
  if (exit_code >= 0) {
    // The sub-process has completed so return here.
    return;
  }

  // Parse command-line arguments for use in this method.
  CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
  command_line->InitFromString(::GetCommandLineW());

  // Create the singleton manager instance.
  ClientManager manager;

  // Specify CEF global settings here.
  CefSettings settings;

  if (command_line->HasSwitch("enable-chrome-runtime")) {
    // Enable experimental Chrome runtime. See issue #2969 for details.
    settings.chrome_runtime = true;
  }
 
  // Initialize CEF.
  CefInitialize(main_args, settings, app, sandbox_info);


CefInitialize is not calling CreateBrowser. If you are basing your code on the cefsimple app provided from CEF, then what is calling CreateBrowser is SimpleApp::OnContextInitialized.

In your code snippet, CefInitialize(main_args, settings, app /* This will implement OnContextInitialized */, sandbox_info);
pascalkhoury
Techie
 
Posts: 25
Joined: Fri Apr 15, 2022 8:21 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby BorjaPascual » Tue Feb 14, 2023 10:26 am

I should slap myself for not seeing it! Thank you! However, now I'm getting this error at browser_process_handler_on_register_custom_preferences() when calling CefBrowserProcessHandlerCppToC::Get():

Code: Select all
 "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."


What I did in my app was:

Code: Select all
void CCefSimpleApp::OnContextInitialized()
{
  //CEF_REQUIRE_UI_THREAD();

  if (!CefCurrentlyOn(TID_UI)) {
    // Execute on the UI thread.
  CefPostTask(TID_UI, base::BindOnce(&CCefSimpleApp::OnContextInitialized, this));
    return;
  }

  CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::GetGlobalCommandLine();

  // Create the browser using the Views framework if "--use-views" is specified
  // via the command-line. Otherwise, create the browser using the native
  // platform framework.
  const bool use_views = command_line->HasSwitch("use-views");

  // SimpleHandler implements browser-level callbacks.
  CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  if (use_views)
  {
    // Create the BrowserView.
    CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
        handler, m_url, browser_settings, nullptr, nullptr,
        new SimpleBrowserViewDelegate());

    // Create the Window. It will show itself after creation.
    CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view));
  }
  else
  {
    // Information used when creating the native window.
    CefWindowInfo window_info;

#if defined(OS_WIN)
    // On Windows we need to specify certain flags that will be passed to
    // CreateWindowEx().
    window_info.SetAsPopup(nullptr, "Nemo Prototype");
#endif

    // Create the first browser window.
    /* CefBrowserHost::CreateBrowser(window_info, handler, url,
                                     browser_settings,
                                  nullptr, nullptr);*/
    CreateBrowser(new minimal::Client(), m_url, CefBrowserSettings());
  }
}
BorjaPascual
Techie
 
Posts: 27
Joined: Mon Jan 30, 2023 11:25 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby pascalkhoury » Tue Feb 14, 2023 10:49 am

BorjaPascual wrote:I should slap myself for not seeing it! Thank you! However, now I'm getting this error at browser_process_handler_on_register_custom_preferences() when calling CefBrowserProcessHandlerCppToC::Get():

Code: Select all
 "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."


What I did in my app was:

Code: Select all
void CCefSimpleApp::OnContextInitialized()
{
  //CEF_REQUIRE_UI_THREAD();

  if (!CefCurrentlyOn(TID_UI)) {
    // Execute on the UI thread.
  CefPostTask(TID_UI, base::BindOnce(&CCefSimpleApp::OnContextInitialized, this));
    return;
  }

  CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::GetGlobalCommandLine();

  // Create the browser using the Views framework if "--use-views" is specified
  // via the command-line. Otherwise, create the browser using the native
  // platform framework.
  const bool use_views = command_line->HasSwitch("use-views");

  // SimpleHandler implements browser-level callbacks.
  CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views));

  // Specify CEF browser settings here.
  CefBrowserSettings browser_settings;

  if (use_views)
  {
    // Create the BrowserView.
    CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
        handler, m_url, browser_settings, nullptr, nullptr,
        new SimpleBrowserViewDelegate());

    // Create the Window. It will show itself after creation.
    CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view));
  }
  else
  {
    // Information used when creating the native window.
    CefWindowInfo window_info;

#if defined(OS_WIN)
    // On Windows we need to specify certain flags that will be passed to
    // CreateWindowEx().
    window_info.SetAsPopup(nullptr, "Nemo Prototype");
#endif

    // Create the first browser window.
    /* CefBrowserHost::CreateBrowser(window_info, handler, url,
                                     browser_settings,
                                  nullptr, nullptr);*/
    CreateBrowser(new minimal::Client(), m_url, CefBrowserSettings());
  }
}



You don't need the CefPostTask because OnContextInitialized will always be called on CEF UI thread.
Code: Select all
void CCefSimpleApp::OnContextInitialized()
{
  //CEF_REQUIRE_UI_THREAD();

  if (!CefCurrentlyOn(TID_UI)) {
    // Execute on the UI thread.
  CefPostTask(TID_UI, base::BindOnce(&CCefSimpleApp::OnContextInitialized, this));
    return;
  }


In this part you are not passing the window_info. Could that be the error or is that a typo
Code: Select all
    // Create the first browser window.
    /* CefBrowserHost::CreateBrowser(window_info, handler, url,
                                     browser_settings,
                                  nullptr, nullptr);*/
    CreateBrowser(new minimal::Client(), m_url, CefBrowserSettings());
pascalkhoury
Techie
 
Posts: 25
Joined: Fri Apr 15, 2022 8:21 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby BorjaPascual » Tue Feb 14, 2023 11:18 am

You don't need the CefPostTask because OnContextInitialized will always be called on CEF UI thread.


It's not in my case, since I am integrating CEF on a bigger, multi threaded app.

In this part you are not passing the window_info. Could that be the error or is that a typo


this part is a call to this function:

Code: Select all
void CreateBrowser(CefRefPtr<CefClient> client,
                   const CefString& startup_url,
                   const CefBrowserSettings& settings)
{
  //CEF_REQUIRE_UI_THREAD();

#if defined(OS_WIN) || defined(OS_LINUX)
  CefRefPtr<CefCommandLine> command_line =
      CefCommandLine::GetGlobalCommandLine();

  // Create the browser using the Views framework if "--use-views" is specified
  // via the command-line. Otherwise, create the browser using the native
  // platform framework. The Views framework is currently only supported on
  // Windows and Linux.
  const bool use_views = command_line->HasSwitch("use-views");
#else
  const bool use_views = false;
#endif

  if (use_views)
  {
    // Create the BrowserView.
    CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
        client, startup_url, settings, nullptr, nullptr, nullptr);

    // Create the Window. It will show itself after creation.
    CefWindow::CreateTopLevelWindow(new WindowDelegate(browser_view));
  }
  else
  {
    // Information used when creating the native window.
    CefWindowInfo window_info;

#if defined(OS_WIN)
    // On Windows we need to specify certain flags that will be passed to
    // CreateWindowEx().
    window_info.SetAsPopup(nullptr, "examples");
#endif

    // Create the browser window.
    CefBrowserHost::CreateBrowser(window_info, client, startup_url, settings,
                                  nullptr, nullptr);
  }
}
BorjaPascual
Techie
 
Posts: 27
Joined: Mon Jan 30, 2023 11:25 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby pascalkhoury » Tue Feb 14, 2023 11:35 am

BorjaPascual wrote:
You don't need the CefPostTask because OnContextInitialized will always be called on CEF UI thread.


It's not in my case, since I am integrating CEF on a bigger, multi threaded app.


Regardless of your app, CEF will call this function on the CEF UI thread.
pascalkhoury
Techie
 
Posts: 25
Joined: Fri Apr 15, 2022 8:21 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby BorjaPascual » Wed Feb 15, 2023 3:04 am

pascalkhoury wrote:Regardless of your app, CEF will call this function on the CEF UI thread.


I'm not sure about that, otherwise CEF_REQUIRE_UI_THREAD() wouldn't be triggered there. Anyway, I'm still having this weird crash at browser_process_handler_on_register_custom_preferences(), line 43, when calling CefBrowserProcessHandlerCppToC::Get(self)->OnRegisterCustomPreferences(): "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."
BorjaPascual
Techie
 
Posts: 27
Joined: Mon Jan 30, 2023 11:25 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby ndesktop » Wed Feb 15, 2023 6:13 am

You are mixing the calling convention (__cdecl or __stdcall), or you link with /MD perhaps? AFAIK only /MT is supported.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby BorjaPascual » Wed Feb 15, 2023 6:43 am

ndesktop wrote:You are mixing the calling convention (__cdecl or __stdcall), or you link with /MD perhaps? AFAIK only /MT is supported.

I'm linking with /MD.

EDIT: Isn't it possible for me to download the library and recompile it using /MD?

EDIT2: I recompiled the CEF solution with /MD and cefsimple runs smoothly, so this shouldn't be the problem
BorjaPascual
Techie
 
Posts: 27
Joined: Mon Jan 30, 2023 11:25 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby ndesktop » Wed Feb 15, 2023 9:03 am

/MT is recommended AFAIK (sandbox for sure supports only /MT).
Also /MD probably works, but make sure you build libcef wrapper and your application with the same option. That is, if the application is also C++.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Crash: Check failed: CefCurrentlyOn(TID_UI)

Postby BorjaPascual » Wed Feb 15, 2023 9:51 am

Yeah, that doesn't seem to be the problem. I don't understand why I'm getting this crash. libcef_dll_wrapper is being compiled in /MD and I'm not using sandbox either.
BorjaPascual
Techie
 
Posts: 27
Joined: Mon Jan 30, 2023 11:25 am

PreviousNext

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 214 guests