Build Error in CefRunMessageLoop Function

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.

Build Error in CefRunMessageLoop Function

Postby Voltageist » Fri Jul 31, 2020 4:20 pm

Hi! I'm new to the forum and the Chromium Embedded Framework so I have a question regarding an error. I am getting the following errors when I try to compile CEF using the following command.

Command:
Code: Select all
g++ -Wall src/entry_main.cpp -I/home/name/Downloads/temp/chrome-to-libbb/CEF src/ClientApp.cpp src/ClientHandler.cpp -Wl,libcef_dll_wrapper.a,libcef.so -g -o build/entry_test


Errors (with logging enabled at v=1):
Code: Select all
[0731/171621.246988:INFO:cpu_info.cc(53)] Available number of cores: 4
[0731/171621.247106:INFO:cpu_info.cc(53)] Available number of cores: 4
[0731/171621.247245:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0731/171621.247089:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0731/171621.248445:VERBOSE1:node_controller.cc(153)] Initializing node 8BFCA0370CE3BA85.A959AA344C7E5243
[0731/171621.249254:INFO:content_main_runner_impl.cc(977)] Chrome is running in full browser mode.
[0731/171621.266084:VERBOSE1:proxy_config_service_linux.cc(500)] All gsettings tests OK. Will get proxy config from gsettings.
[0731/171621.266277:VERBOSE1:proxy_config_service_linux.cc(1261)] Obtained proxy settings from annotation hash code 11258689
[0731/171621.266368:VERBOSE1:pref_proxy_config_tracker_impl.cc(185)] 0x55b5204a3ab0: set chrome proxy config service to 0x55b5204a6a00
[0731/171621.266986:VERBOSE1:font_render_params_linux.cc(211)] Computing params for 1794297614
[0731/171621.268281:ERROR:viz_process_transport_factory.cc(308)] Switching to software compositing.
[0731/171621.268559:VERBOSE1:webrtc_internals.cc(119)] Could not get the download directory.
[0731/171621.269864:VERBOSE1:media_stream_manager.cc(685)] MSM::InitializeMaybeAsync([this=0x55b5204b3c60])
[0731/171621.269915:VERBOSE1:media_stream_manager.cc(685)] MDM::MediaDevicesManager()
[0731/171621.269949:VERBOSE1:media_stream_manager.cc(685)] MSM::MediaStreamManager([this=0x55b5204b3c60]))
[0731/171621.270550:ERROR:edid_parser.cc(102)] Too short EDID data: manufacturer id
[0731/171621.272423:VERBOSE1:memory_linux.cc(100)] Adjusting oom_score_adj of 16217 to 200
[0731/171621.272863:FATAL:field_trial.cc(445)] Check failed: !global_.
[0731/171621.285859:VERBOSE1:proxy_config_service_linux.cc(500)] All gsettings tests OK. Will get proxy config from gsettings.
[0731/171621.286044:VERBOSE1:proxy_config_service_linux.cc(1261)] Obtained proxy settings from annotation hash code 11258689
[0731/171621.286109:VERBOSE1:pref_proxy_config_tracker_impl.cc(185)] 0x55b5205e6dd0: set chrome proxy config service to 0x55b5205eb590
[0731/171621.294114:VERBOSE1:node.cc(492)] Merging local ports 94CF4535E53E98F.A0A0CDBBDA0D74E9@8BFCA0370CE3BA85.A959AA344C7E5243 and 8A5BFBBBE1A3C6E2.EB6B6B755286D9B6@8BFCA0370CE3BA85.A959AA344C7E5243
[0731/171621.295218:VERBOSE1:font_render_params_linux.cc(203)] Returning cached params for 1794297614
[0731/171621.301512:VERBOSE1:font_render_params_linux.cc(203)] Returning cached params for 1794297614
[0731/171621.307884:VERBOSE1:x11_event_source.cc(211)] Making a round trip to get a recent server timestamp.
[0731/171621.308417:VERBOSE1:x11_event_source.cc(211)] Making a round trip to get a recent server timestamp.
X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  42 (X_SetInputFocus)
  Serial number of failed request:  267
  Current serial number in output stream:  269
[0731/171621.311325:FATAL:context.cc(58)] Check failed: !g_context. CefShutdown was not called
[0731/171621.312383:FATAL:field_trial.cc(445)] Check failed: !global_.
Trace/breakpoint trap (core dumped)


Here are the files that I'm using for some context.

main.cpp
Code: Select all
#include <thread>
#include <chrono>

#include <include/internal/cef_linux.h>

#include <include/cef_app.h>
#include <include/cef_browser.h>
#include <include/cef_frame.h>

#include "ClientHandler.h"
#include "ClientApp.h"

void CefInitSettings(CefSettings& settings)
{
    CefString(&settings.resources_dir_path) = CefString();
    CefString(&settings.locales_dir_path) = CefString();

    settings.multi_threaded_message_loop = false;
    settings.ignore_certificate_errors = false;

    #if !defined(CEF_USE_SANDBOX)
        settings.no_sandbox = true;
    #endif
}

int main(int argc, char* argv[])
{
    CefMainArgs main_args(argc, argv);

    CefRefPtr<ClientApp> app(new ClientApp);

    CefSettings settings;
    CefInitSettings(settings);

    CefString(&settings.locales_dir_path) = "/my/path/to/locales";
    CefString(&settings.resources_dir_path) = "/my/path/to/resource/directory/";

    CefInitialize(main_args, settings, app.get(), NULL);

    CefRunMessageLoop();
    CefShutdown();

    return 0;
}


ClientApp.cpp (I can share ClientApp.h as well, if required)
Code: Select all
#include "ClientApp.h"
#include "ClientHandler.h"

#include <include/wrapper/cef_helpers.h>
#include <include/views/cef_browser_view.h>

ClientApp::ClientApp()
{
    printf("ClientApp constructor\n");
}

void
ClientApp::OnContextInitialized()
{
    CEF_REQUIRE_UI_THREAD();

    CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine();
 
    CefRefPtr<ClientHandler> handler(new ClientHandler());

    CefBrowserSettings browser_settings;

    std::string url;
    url = command_line->GetSwitchValue("url");
    if (url.empty())
    {
        url = "http://www.google.com";
    }
    CefWindowInfo window_info;

    CefBrowserHost::CreateBrowser(window_info, handler, url, browser_settings, NULL, NULL);
}

void
ClientApp::OnBeforeCommandLineProcessing(
  const CefString& process_type,
  CefRefPtr<CefCommandLine> command_line)
{
    command_line->AppendSwitch("disable-gpu");
    command_line->AppendSwitch("enable-logging");
    command_line->AppendSwitchWithValue("v", "1");
}


ClientHandler.cpp (I can share ClientHandler.h as well, if required)
Code: Select all
#include "ClientHandler.h"

#include <sstream>
#include <string>

#include <include/base/cef_bind.h>
#include <include/cef_app.h>
#include <include/cef_parser.h>
#include <include/views/cef_browser_view.h>
#include <include/views/cef_window.h>
#include <include/wrapper/cef_closure_task.h>
#include <include/wrapper/cef_helpers.h>

ClientHandler *g_instance = NULL;

std::string
GetDataURI(
    const std::string& data,
    const std::string& mime_type)
{
    return "data:" + mime_type + ";base64," + CefURIEncode(CefBase64Encode(data.data(), data.size()), false).ToString();
}

ClientHandler::ClientHandler()
{
    printf("ClientHandler constructor\n");
    is_closing_ = false;
    DCHECK(!g_instance);
    g_instance = this;
}

ClientHandler::~ClientHandler()
{
    printf("ClientHandler destructor\n");
    g_instance = NULL;
}

ClientHandler *
ClientHandler::GetInstance()
{
  return g_instance;
}

void
ClientHandler::OnAfterCreated(
    CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

    browser_list_.push_back(browser);
}

bool
ClientHandler::DoClose(
    CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

    if (browser_list_.size() == 1)
    {
        is_closing_ = true;
    }

    return false;
}

void
ClientHandler::OnBeforeClose(
    CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();

    BrowserList::iterator bit = browser_list_.begin();
    for (; bit != browser_list_.end(); ++bit)
    {
        if ((*bit)->IsSame(browser))
        {
            browser_list_.erase(bit);
            break;
        }
    }

    if (browser_list_.empty())
    {
        CefQuitMessageLoop();
    }
}

void
ClientHandler::OnLoadError(
    CefRefPtr<CefBrowser> browser,
    CefRefPtr<CefFrame> frame,
    ErrorCode errorCode,
    const CefString& errorText,
    const CefString& failedUrl)
{
    CEF_REQUIRE_UI_THREAD();

    /* Don't display an error for downloaded files */
    if (errorCode == ERR_ABORTED)
    {
        return;
    }

    std::stringstream ss;
    ss << "<html><body bgcolor=\"white\">"
          "<h2>Failed to load URL "
       << std::string(failedUrl) << " with error " << std::string(errorText)
       << " (" << errorCode << ").</h2></body></html>";

    frame->LoadURL(GetDataURI(ss.str(), "text/html"));
}

void
ClientHandler::CloseAllBrowsers(
    bool force_close)
{
    if (!CefCurrentlyOn(TID_UI))
    {
      CefPostTask(TID_UI, base::Bind(&ClientHandler::CloseAllBrowsers, this, force_close));
      return;
    }

    if (browser_list_.empty())
    {
          return;
    }

    BrowserList::const_iterator it = browser_list_.begin();
    for (; it != browser_list_.end(); ++it)
    {
          (*it)->GetHost()->CloseBrowser(force_close);
    }
}


Also, this is the current contents of my directory:
Code: Select all
build                debug.log               libGLESv2.so
CEF                  devtools_resources.pak  locales
cef_100_percent.pak  files                   media
cef_200_percent.pak  GPUCache                snapshot_blob.bin
cef_extensions.pak   icudtl.dat              src
cef.pak              libcef_dll_wrapper.a    swiftshader
cefsimple            libcef.so               v8_context_snapshot.bin


My ClientApp and ClientHandler were based off of the Linux example for cefsimple, but converted to C++. I'm very new to all of this so any help would be appreciated. I can provide you with any information you require, so just let me know.
Voltageist
Techie
 
Posts: 16
Joined: Fri Jul 31, 2020 9:37 am

Re: Build Error in CefRunMessageLoop Function

Postby Czarek » Fri Jul 31, 2020 5:58 pm

What is the stack trace? Use gdb tool to obtain it.

Don't call frame->LoadURL from within OnLoadError call stack. Use CefPostTaskDelayed with some timeout to execute it after OnLoadError completes to avoid issues.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Build Error in CefRunMessageLoop Function

Postby magreenblatt » Fri Jul 31, 2020 10:08 pm

There are platform defines that need to be set correctly. I suggest you use the included CMake configuration when building. See the README.txt file for usage instructions.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Build Error in CefRunMessageLoop Function

Postby Voltageist » Tue Aug 04, 2020 4:23 pm

Czarek wrote:What is the stack trace? Use gdb tool to obtain it.

Don't call frame->LoadURL from within OnLoadError call stack. Use CefPostTaskDelayed with some timeout to execute it after OnLoadError completes to avoid issues.


Sorry about the delayed response. I'm assuming this is my backtrace:

Code: Select all
Thread 1 "entry_test" received signal SIGTRAP, Trace/breakpoint trap.
0x00007ffff18bf8bb in operator() () at ../../base/logging.cc:953
953   ../../base/logging.cc: No such file or directory.
(gdb) backtrace
#0  0x00007ffff18bf8bb in operator() () at ../../base/logging.cc:953
#1  0x00007ffff18bf8bb in ~LogMessage() () at ../../base/logging.cc:953
#2  0x00007ffff1749a37 in ~CefShutdownChecker() ()
    at ../../cef/libcef/browser/context.cc:58
#3  0x00007fffeb54f6c5 in __cxa_finalize (d=0x7ffff7bb9500)
    at cxa_finalize.c:83
#4  0x00007fffedb7d833 in __do_global_dtors_aux ()
    at /home/user/Downloads/temp/libcef.so
#5  0x00007fffffffc250 in  ()
#6  0x00007ffff7de5bc3 in _dl_fini () at dl-fini.c:138


I've change the frame->LoadURL, but unfortunately my program never reached that point in it's trace.
Last edited by Voltageist on Tue Aug 04, 2020 5:23 pm, edited 2 times in total.
Voltageist
Techie
 
Posts: 16
Joined: Fri Jul 31, 2020 9:37 am

Re: Build Error in CefRunMessageLoop Function

Postby Voltageist » Tue Aug 04, 2020 4:25 pm

magreenblatt wrote:There are platform defines that need to be set correctly. I suggest you use the included CMake configuration when building. See the README.txt file for usage instructions.


Unfortunately for my current project, I need to build my binary via g++ rather than CMake. But I can look into the CMake files and maybe I'm missing g++/gcc flags.
Voltageist
Techie
 
Posts: 16
Joined: Fri Jul 31, 2020 9:37 am

Re: Build Error in CefRunMessageLoop Function

Postby magreenblatt » Tue Aug 04, 2020 4:39 pm

CMake is a build system that generates project files in a range of different formats. It can be used to build with gcc (which is the compiler).
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Build Error in CefRunMessageLoop Function

Postby Voltageist » Tue Aug 04, 2020 4:54 pm

magreenblatt wrote:CMake is a build system that generates project files in a range of different formats. It can be used to build with gcc (which is the compiler).


Oh, I think I understand! Do you have any links to explain this in further detail? Sorry, I'm very new in this entire field, a lot of this is pretty foreign to me.
Voltageist
Techie
 
Posts: 16
Joined: Fri Jul 31, 2020 9:37 am

Re: Build Error in CefRunMessageLoop Function

Postby magreenblatt » Tue Aug 04, 2020 5:39 pm

You can find build instructions for CEF in the binary distribution’s top-level CMakeLists.txt file. More information about CMake can be found at https://cmake.org/overview/.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: Build Error in CefRunMessageLoop Function

Postby Voltageist » Wed Aug 05, 2020 11:43 am

magreenblatt wrote:You can find build instructions for CEF in the binary distribution’s top-level CMakeLists.txt file. More information about CMake can be found at https://cmake.org/overview/.


Thanks again! Quick question, does anything in my stacktrace above from gdb stand out to you?
Voltageist
Techie
 
Posts: 16
Joined: Fri Jul 31, 2020 9:37 am

Re: Build Error in CefRunMessageLoop Function

Postby magreenblatt » Wed Aug 05, 2020 11:55 am

What, specifically, is the problem? Is your application terminating unexpectedly? Or is it just the crash on shutdown?

Your stack trace is from this error:
[0731/171621.311325:FATAL:context.cc(58)] Check failed: !g_context. CefShutdown was not called
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Next

Return to Support Forum

Who is online

Users browsing this forum: kimcey and 48 guests