包括 Boost ASIO 与 Amazon Gamelift SDK 冲突

Including Boost ASIO conflicts with Amazon Gamelift SDK

如果我在没有任何实际使用 boost::asio 的头文件中包含 boost ASIO,在我调用 Aws::GameLift::Server::InitSDK() 的任何时候,应用程序都会从​​另一个线程崩溃。这怎么可能?

Exception thrown at 0x00007FFC4ADEA6AB (ntdll.dll) in MyApp.exe: 0xC0000005: Access violation writing location 0x0000000100000023.

ntdll.dll!RtlpWaitOnCriticalSection()   Unknown
ntdll.dll!RtlpEnterCriticalSectionContended()   Unknown
ntdll.dll!RtlEnterCriticalSection() Unknown
MyApp.exe!boost::asio::detail::win_iocp_io_service::do_add_timer_queue(class boost::asio::detail::timer_queue_base &)   C++
MyApp.exe!boost::asio::waitable_timer_service<struct std::chrono::steady_clock,struct boost::asio::wait_traits<struct std::chrono::steady_clock> >::waitable_timer_service<struct std::chrono::steady_clock,struct boost::asio::wait_traits<struct std::chrono::steady_clock> >(class boost::asio::io_service &)    C++
MyApp.exe!boost::asio::detail::service_registry::create<class boost::asio::waitable_timer_service<struct std::chrono::steady_clock,struct boost::asio::wait_traits<struct std::chrono::steady_clock> > >(class boost::asio::io_service &)   C++
MyApp.exe!boost::asio::detail::service_registry::do_use_service(const boost::asio::io_service::service::key & key, boost::asio::io_service::service *(*)(boost::asio::io_service &) factory) Line 124   C++
MyApp.exe!boost::asio::detail::win_iocp_io_service::do_one(bool block, boost::system::error_code & ec) Line 397 C++
MyApp.exe!boost::asio::detail::win_iocp_io_service::run(boost::system::error_code & ec) Line 159    C++ 

这是我的 include - 将它放在任何头文件的顶部都会在 InitSDK 调用后触发异常。

#define BOOST_ASIO_HAS_MOVE
#define CreateEvent CreateEventA
#include <boost/asio.hpp>
#undef CreateEvent

我正在使用:

我看过这个问题:

当我添加#define BOOST_ASIO_DISABLE_IOCP时,异常发生变化,调用堆栈在主线程上。这让我相信它与套接字服务的不同实现有关,具体取决于使用的定义。

MyApp.exe!boost::asio::detail::win_iocp_socket_service_base::construct(struct boost::asio::detail::win_iocp_socket_service_base::base_implementation_type &)    C++
MyApp.exe!boost::asio::basic_io_object<class boost::asio::socket_acceptor_service<class boost::asio::ip::tcp>,1>::basic_io_object<class boost::asio::socket_acceptor_service<class boost::asio::ip::tcp>,1>(class boost::asio::io_service &)    C++
MyApp.exe!std::make_shared<class boost::asio::basic_socket_acceptor<class boost::asio::ip::tcp,class boost::asio::socket_acceptor_service<class boost::asio::ip::tcp> >,class boost::reference_wrapper<class boost::asio::io_service> const >(class boost::reference_wrapper<class boost::asio::io_service> const &&)   C++
MyApp.exe!websocketpp::transport::asio::endpoint<struct websocketpp::config::asio_client::transport_config>::init_asio(class boost::asio::io_service *,class std::error_code &) C++
MyApp.exe!websocketpp::transport::asio::endpoint<struct websocketpp::config::asio_client::transport_config>::init_asio(class boost::asio::io_service *) C++
MyApp.exe!sio::client_impl::client_impl(void)   C++
MyApp.exe!sio::client::client(void) C++
MyApp.exe!Aws::GameLift::Internal::GameLiftServerState::InitializeNetworking(void)  Unknown
MyApp.exe!Aws::GameLift::Server::InitSDK(void)  Unknown

看来我使用的 Gamelift SDK 版本使用的是 Boost 1.61,这与我在主项目中使用的 Boost 1.52 冲突。

我将我对 Boost 的使用升级到 1.61 以匹配他们的,并且突然间 - Gamelift 不再有例外。惊喜。