ValveSoftware / GameNetworkingSockets

Reliable & unreliable messages over UDP. Robust message fragmentation & reassembly. P2P networking / NAT traversal. Encryption.
BSD 3-Clause "New" or "Revised" License
8.18k stars 615 forks source link

ISteamNetworkingMessages.ReceiveMessagesOnChannel blocks forever sometimes #324

Open winterSteve25 opened 2 months ago

winterSteve25 commented 2 months ago

Hey, I am working on a little cpp project using steam networking and ISteamNetworkingMessages.ReceiveMessagesOnChannel call sometimes blocks forever.

I have class NetworkManager and in the constructor uses malloc to allocate a buffer for message pointers, and every update frame I am calling ReceiveMessagesOnChannel and sometimes this call blocks forever causing the application to freeze up, I was wondering if there is something I am doing wrong or missing

This is on windows x64

Thank you very much for your time!

zpostfacto commented 1 month ago

Is this using the steamworks code or the opensource code here? Can you give me a call stack, or capture a minidump, of this happening?

winterSteve25 commented 1 month ago

I'm using the steamworks sdk with their headers and precompiled dll, this is the callstack when the call to ISteamNetworkingMessages.ReceiveMessagesOnChannel occurs.

image

This is the function:

void NetworkManager::HandleMessages()
{
    int msgCount = SteamNetworkingMessages()->ReceiveMessagesOnChannel(0, m_messageBuffer, message_buffer_size);
    if (msgCount <= 0) return;

    for (int i = 0; i < msgCount; i++)
    {
        SteamNetworkingMessage_t* msg = m_messageBuffer[i];
        HandleMessage(msg);
        msg->Release();
    }
}

m_messageBuffer is type of SteamNetworkingMessage_t** initialized like so in the constructor static_cast<SteamNetworkingMessage_t**>(malloc(message_buffer_size * sizeof(SteamNetworkingMessage_t*)))

and message_buffer_size is a constexpr of 64