简体   繁体   English

在特定DLL中调用函数时,CEF崩溃

[英]CEF crashes when calling functions in a particular DLL

I have an MSVC project, this project consists of multiple DLLs called from an executable. 我有一个MSVC项目,该项目包含从一个可执行文件调用的多个DLL。 One of these DLLs initializes CEF (Chromium Embedded Framework) and another provides some other general functionality, We'll call them cefDLL and generalDLL. 这些DLL之一初始化CEF(铬嵌入式框架),另一个提供其他常规功能,我们将其称为cefDLL和generalDLL。 The calls go like this: 呼叫如下:

  1. All the calls are done from the executable. 所有调用均从可执行文件完成。
  2. I call functions in the cefDLL to initialize CEF. 我在cefDLL中调用函数来初始化CEF。
  3. I call functions the second generalDLL. 我将函数称为第二个generalDLL。
  4. Some thread internally in CEF crashes with a Windows error popup reporting "The application was unable to start correct (0xc0000124). Click OK to close the application.". CEF内部的某些线程崩溃,并显示Windows错误弹出窗口,提示“应用程序无法正确启动(0xc0000124)。单击“确定”关闭该应用程序。”。
  5. A Windows popup appears declaring Application.exe has stopped working. 出现Windows弹出窗口,声明Application.exe已停止工作。
  6. The main thread continues running even if I close the program on the "has stopped working" popup. 即使我在“已停止工作”弹出窗口中关闭程序,主线程仍继续运行。

If I try to run the debugger on the crashed program I get a blank Visual Studio, no call stack, no locals, nothing, not even the name of a failed DLL. 如果我尝试在崩溃的程序上运行调试器,则会得到一个空白的Visual Studio,没有调用堆栈,没有本地变量,没有任何东西,甚至没有失败的DLL的名称。

If I call a function from another DLL, a function from the executable itself or none at all, the code reaches my infinite loop just fine (I'm using an infinite loop to stop the rest of the program from running). 如果我从另一个DLL调用一个函数,或者从可执行文件本身调用一个函数,或者根本不调用一个函数,则代码到达我的无限循环就好了(我正在使用无限循环来阻止程序的其余部分运行)。

If I let it keep running into the rest of the program and don't stop it with an infinite loop two more threads in CEF crash for a total of three crashed threads. 如果我让它继续运行到程序的其余部分,并且不通过无限循环来停止它,则CEF崩溃时还会有另外两个线程,总共三个崩溃的线程。 These produce exactly the same errors as the first thread. 这些产生与第一个线程完全相同的错误。 I'm not sure what causes this precisely as I haven't had the time to look into this yet. 我不确定是什么原因造成的,因为我还没有时间对此进行研究。

Even if the functions called in generalDLL do absolutely nothing this still occurs. 即使在generalDLL中调用的函数绝对不执行任何操作,这仍然会发生。 I am certain it is the act of calling them that causes this, if my code is 我敢肯定,如果我的代码是

initializeCEF();

while (true)
{

}

it works, if the code is 如果代码是

initializeCEF();

someBlankFunctionInGeneralDLL();

while (true)
{

}

the thread crashes. 线程崩溃。

The initialization of CEF consists of this: CEF的初始化包含以下内容:

//Initialize
CefMainArgs mainArgs;

//Launch Threads
CefExecuteProcess(mainArgs, nullptr, nullptr);

//Settings
CefSettings settings;
settings.pack_loading_disabled = true;
settings.windowless_rendering_enabled = true;
settings.multi_threaded_message_loop = false;
settings.no_sandbox = true;

//Sandbox Info
void *sandboxInfo = nullptr;

//Launch System
CefInitialize(mainArgs, settings, nullptr, sandboxInfo);

Does anyone have the faintest idea what this could be caused by? 有谁知道这可能是由什么引起的? It's easily among the strangest bugs I've ever encountered. 这很容易是我遇到过的最奇怪的错误之一。 The project is giant at 50,000 lines or so and there aren't really any other relevant parts so I can't really provide any examples I'm afraid. 该项目规模巨大,大约有50,000条线,实际上没有任何其他相关部分,因此我无法提供我担心的任何示例。 Let me know if there's some code you think it would help to see though. 让我知道您是否认为有一些代码会有所帮助。

You know CEF is multi-process, right? 您知道CEF是多进程的,对吗? Is it possible that your main application that is initializing CEF is not able to start multiple instances correctly, or is not passing the required command-line arguments to your CEF-containing DLL at startup? 您正在初始化CEF的主应用程序是否可能无法正确启动多个实例,或者在启动时未将所需的命令行参数传递给包含CEF的DLL? See this documentation about the structure of CEF applications: https://bitbucket.org/chromiumembedded/cef/wiki/Architecture#markdown-header-cef3 请参阅有关CEF应用程序结构的此文档: https : //bitbucket.org/chromiumembedded/cef/wiki/Architecture#markdown-header-cef3

You can try starting CEF with the "--single-process" argument to force it to run single process (though shipping with this is very much not recommended because they don't test Chromium in this configuration - it is just for debugging). 您可以尝试使用“ --single-process”参数来启动CEF,以强制其运行单个进程(尽管不建议使用此程序进行运送,因为它们不会在此配置中测试Chromium,这仅用于调试)。 If you are not passing command line arguments to CEF that is probably the start of your problems. 如果您没有将命令行参数传递给CEF,则可能是问题的开始。 To do this, you can add a handler for OnBeforeCommandLineProcessing() in you CefApp derived class, as recommended by the creator of CEF here: http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=12928&p=25732&hilit=main_args#p25717 . 为此,您可以按照CEF创建者的建议,在CefApp派生类中为OnBeforeCommandLineProcessing()添加处理程序: http : //www.magpcss.org/ceforum/viewtopic.php ?f=6&t=12928&p = 25732&hilit = main_args#p25717 The override would end up looking something like this: 覆盖最终看起来像这样:

void ServiceCenterApp::OnBeforeCommandLineProcessing(const CefString& process_type,
                                                 CefRefPtr<CefCommandLine> command_line) {

if(!command_line->HasSwitch("single-process")) {
    command_line->AppendSwitch("single-process");
}

} }

But I don't see you defining a CefApp derived class, that would be an argument to CefInitialize(). 但是我看不到您定义CefApp派生类,这将成为CefInitialize()的参数。 For example, the cefclient sample has this in their wWinMain(): 例如,cefclient示例在其wWinMain()中具有以下内容:

 // SimpleApp implements application-level callbacks. It will create the first
  // browser instance in OnContextInitialized() after CEF has initialized.
  CefRefPtr<SimpleApp> app(new SimpleApp);

followed by 其次是

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get(), sandbox_info);

Where you tell CEF to use the derived App, where you would override whatever handlers you need to. 在告诉CEF使用派生的App的地方,您将覆盖需要的任何处理程序。 You might want to start with the simple_app sample for a very basic override. 您可能要从simple_app示例开始,以进行非常基本的覆盖。

For the debugging issue, try attaching to all processes launched, assuming I'm incorrect and the multiple processes are launching correctly. 对于调试问题,请尝试附加到所有启动的进程,假设我不正确并且多个进程正在正确启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM