C++ GameNetworkingSockets running results in null pointer cannot point to a block of non-zero size

I’m working on a chat application using C++ and the GameNetworkingSockets library for networking in Visual Studio 2022. I’ve built the library according to the github page (github) and then set up my project including the .lib file and all dependencies in my Project Settings.

Reproducible Example:
I have created a reproducible example (as far as i have understood what it is)

#include "steam/steamnetworkingsockets.h"
int main() {
    // Initialize the SteamNetworkingSockets library
    SteamDatagramErrMsg errMsg;
    GameNetworkingSockets_Init(nullptr, errMsg);

    // Create the ISteamNetworkingSockets interface
    ISteamNetworkingSockets* m_Interface = SteamNetworkingSockets();

    // Set up the server address
    SteamNetworkingIPAddr serverAddress;
    serverAddress.Clear();
    serverAddress.ParseString("127.0.0.1");
    serverAddress.m_port = 27020;

    // Display the server address
    char szAddr[SteamNetworkingIPAddr::k_cchMaxString];
    serverAddress.ToString(szAddr, sizeof(szAddr), true);
    //Printf("Connecting to server at %sn", szAddr);

    // Attempt to connect
    HSteamNetConnection m_Connection = m_Interface->ConnectByIPAddress(serverAddress, 0, nullptr);
    m_Connection == k_HSteamNetConnection_Invalid;

    // Cleanup
    GameNetworkingSockets_Kill();

    return 0;
}

Running this will result in the following assertion failing (xmemory file):

_CONSTEXPR20 void deallocate(_Ty* const _Ptr, const size_t _Count) {
    _STL_ASSERT(_Ptr != nullptr || _Count == 0, "null pointer cannot point to a block of non-zero size");
    // no overflow check on the following multiply; we assume _Allocate did that check
    _Deallocate<_New_alignof<_Ty>>(_Ptr, sizeof(_Ty) * _Count);
}

With the following Error Message:

Debug Assertion Failed!

Program: C:UsersalexlsourcereposChatx64DebugChat.exe
File: D:VisualStudioVCToolsMSVC14.36.32532includexmemory
Line: 944

Expression: null pointer cannot point to a block of non-zero size

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

Call stack:

>   Chat.exe!std::allocator<char>::deallocate(char * const _Ptr, const unsigned __int64 _Count) Line 944    C++
    Chat.exe!std::string::_Tidy_deallocate() Line 4877  C++
    Chat.exe!std::string::~basic_string<char,std::char_traits<char>,std::allocator<char>>() Line 3159   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::SetLocalCertUnsigned() Line 1314   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::BThinkCryptoReady(__int64 usecNow) Line 1090   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::InitConnectionCrypto(__int64 usecNow) Line 1029    C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::BInitConnection(__int64 usecNow, int nOptions, const SteamNetworkingConfigValue_t * pOptions, char[1024] & errMsg) Line 987    C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionUDP::BInitConnect(const SteamNetworkingIPAddr & addressRemote, int nOptions, const SteamNetworkingConfigValue_t * pOptions, char[1024] & errMsg) Line 1199   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkingSockets::ConnectByIPAddress(const SteamNetworkingIPAddr & address, int nOptions, const SteamNetworkingConfigValue_t * pOptions) Line 1135   C++
    Chat.exe!main() Line 140    C++
    [External Code] 

I have noticed that at the point where ~basic_string is called the this std::string pointer is NULL: + this 0x0000003927f2ee38 <NULL> std::string *. Is a string destructor being called on a non-existent string?

Maybe it has to do with how i set up my project with linking all the dependencies or the version of some libraries because everything else should be working fine and i am only using one function ConnectByIPAddress() where it seems to go wrong.

Instead of the Debug Assertion failed error, sometimes i will get read or write access violation exception also in xmemory file:

_CONSTEXPR20 void _Container_base12::_Orphan_all_unlocked_v3() noexcept {
    if (!_Myproxy) { // no proxy, already done
        return;
    }

    // proxy allocated, drain it
    for (auto _Pnext = _STD exchange(_Myproxy->_Myfirstiter, nullptr); _Pnext; _Pnext = _Pnext->_Mynextiter) {
        _Pnext->_Myproxy = nullptr;
    }
}

Call Stack:

>   Chat.exe!std::_Container_base12::_Orphan_all_unlocked_v3() Line 1349    C++
    Chat.exe!std::_Container_base12::_Orphan_all_locked_v3() Line 1205  C++
    Chat.exe!std::_Container_base12::_Orphan_all() Line 1364    C++
    Chat.exe!std::string::_Tidy_deallocate() Line 4868  C++
    Chat.exe!std::string::~basic_string<char,std::char_traits<char>,std::allocator<char>>() Line 3159   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::SetLocalCertUnsigned() Line 1314   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::BThinkCryptoReady(__int64 usecNow) Line 1090   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::InitConnectionCrypto(__int64 usecNow) Line 1029    C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionBase::BInitConnection(__int64 usecNow, int nOptions, const SteamNetworkingConfigValue_t * pOptions, char[1024] & errMsg) Line 987    C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkConnectionUDP::BInitConnect(const SteamNetworkingIPAddr & addressRemote, int nOptions, const SteamNetworkingConfigValue_t * pOptions, char[1024] & errMsg) Line 1199   C++
    Chat.exe!SteamNetworkingSocketsLib::CSteamNetworkingSockets::ConnectByIPAddress(const SteamNetworkingIPAddr & address, int nOptions, const SteamNetworkingConfigValue_t * pOptions) Line 1135   C++
    Chat.exe!main() Line 140    C++
    [External Code] 

Error Message:

Exception thrown: write access violation.
**_Pnext** was 0x20.

3

So the problem really was with my setup of the project. I don’t exactly know where or what but it seems i might have missed to include some of the dependencies of the networking library i am using. I have created a new project, included every dependency in the project settings and now it’s working fine. That could have been avoided pretty easily but now i know better.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật