现象:
chrome源码3.2623.1397.gaf139d7加入mp3支持,在win7下很稳定。在xp下崩溃无法运行。
解决过程:
1.加入调试语句,发现只要碰到函数static变量,就会崩溃。例如以下代码
void AddInternalSchemes(std::vector<std::string>* standard_schemes,
std::vector<std::string>* savable_schemes) {
// chrome: and chrome-devtools: schemes are registered in
// RenderThreadImpl::RegisterSchemes().
// Access restrictions for chrome-extension: and chrome-extension-resource:
// schemes will be applied in CefContentRendererClient::WillSendRequest
//qsy
DLOG(INFO) << "test crashed";
static CefContentClient::SchemeInfo schemes[2] = {
{ extensions::kExtensionScheme, true, true, false, false },
{ extensions::kExtensionResourceScheme, true, true, false, false },
};
//qsy
DLOG(INFO) << "no crashed";
2.尝试在CEF_INITIALIZE函数也加这个类型的static赋值,一样碰到赋值语句就崩溃,底下语句都没有执行。
3.不断的尝试,不断的猜想,百思不得其解,尝试了3天。于是各种请教搜索引擎,历时2天,搜索yahoo.关键字
xp static variable exception
得出这篇
http://stackoverflow.com/questions/32517234/access-violation-on-static-initialization
这篇指出:
Windows Server 2003 and Windows XP have problems with dynamically loading a DLL (via LoadLibrary) that uses thread-local storage, which is what thread-safe statics use internally to provide efficient execution when the static local has already been initialized. As these systems are out of support, it is extremely unlikely for a patch to be created for those systems to add this support as is present in Vista and newer OSes, and we are reluctant to penalize the performance on in-support OSes to provide this functionality to the old out-of-support ones.
To work around the issue you can use /Zc:threadSafeInit- to disable the thread-safe initialization code and this will avoid the thread-local variable. Of course by doing so the initialization code reverts back to the VS2013 mode and is not thread-safe, so this option is only viable if you don't rely on the thread-safety of local statics.
为了解决这个问题可以加入编译选项:/Zc:threadSafeInit-
修改源码chromium\src\build\common.gypi
3238行为:'Common_Base':
在3300行加入::'/Zc:threadSafeInit-',
附近代码为:
['OS=="win" and MSVS_VERSION == "2015"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
# Work around crbug.com/526851, bug in VS 2015 RTM compiler.
'/Zc:sizedDealloc-',
'/Zc:threadSafeInit-',
],
},
},
}],
再次重新编译。
重新编译后,xp总算可以正常运行了.