版权声明:www.gudianxiaoshuo.com (古典小说网) 今日头条号: 古典古韵古典小说、讨厌编程 https://blog.csdn.net/shuilan0066/article/details/83307088
1,当网页中有自定义视频控件时,结束程序,关闭CEF时,会发生中断到libcef.dll中
方法:
1)可以去掉这样的控件,正常的网站是可以正常结束的
2)不能替换这样的控件的话,因为只在结束中,有中断
所以强制结束,也不会有什么影响,所以可以强制关闭进程
//当网页中有网易自定义的视频控件时,退出有问题,中断到libcef.dll中, 为避免这样无效的中断,退出时,强制结束自己的进程
HANDLE hself = GetCurrentProcess();
TerminateProcess(hself, 0);
2 单进程,多进程模式设置
在CefInitialize 初始化时,设置相关的模式
如:
void CefManager::GetCefSetting(const std::wstring& app_data_dir, CefSettings &settings)
{
if (false == nbase::FilePathIsExist(app_data_dir, true))
nbase::CreateDirectory(app_data_dir);
#if !defined(SUPPORT_CEF_FLASH)
settings.no_sandbox = true;
#endif
// 设置localstorage,不要在路径末尾加"\\",否则运行时会报错
CefString(&settings.cache_path) = app_data_dir + L"CefLocalStorage";
// 设置debug log文件位置
CefString(&settings.log_file) = app_data_dir + L"cef.log";
// 调试模型下使用单进程,但是千万不要在release发布版本中使用,官方已经不推荐使用单进程模式
// cef1916版本debug模式:在单进程模式下程序退出时会触发中断
#ifdef _DEBUG
settings.single_process = true;
#else
settings.single_process = false;
#endif
// cef2623、2526版本debug模式:在使用multi_threaded_message_loop时退出程序会触发中断
// 加入disable-extensions参数可以修复这个问题,但是会导致一些页面打开时报错
// 开启Cef多线程消息循环,兼容nbase库消息循环
settings.multi_threaded_message_loop = true;
// 开启离屏渲染
settings.windowless_rendering_enabled = is_enable_offset_render_;
}
CefMainArgs main_args(GetModuleHandle(NULL));
CefRefPtr<ClientApp> app(new ClientApp);
// 如果是在子进程中调用,会堵塞直到子进程退出,并且exit_code返回大于等于0
// 如果在Browser进程中调用,则立即返回-1
int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
if (exit_code >= 0)
return false;
GetCefSetting(app_data_dir, settings);
bool bRet = CefInitialize(main_args, settings, app.get(), sandbox_info);