From 33c7d6903e843d450eb18769d5802e83de538825 Mon Sep 17 00:00:00 2001 From: Maxim <46995666+Vincenz099@users.noreply.github.com> Date: Tue, 7 Apr 2020 11:58:08 +0200 Subject: [PATCH 1/4] Return 0 instead of -1 on enet_protocol_receive_incoming_commands Return 0 instead of -1 on enet_protocol_receive_incoming_commands when nothing received. This allows the Service loop to continue running and not return an error when there is nothing to do with the socket receive. From debugging I found sometimes the enet_protocol_receive_incoming_commands returns -1 because simply nothing happened in the 256 for loop. Other functions like enet_protocol_send_outgoing_commands return 0 when nothing happened. --- protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol.c b/protocol.c index 98ee51e..a1d7ee1 100644 --- a/protocol.c +++ b/protocol.c @@ -1288,7 +1288,7 @@ enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event) } } - return -1; + return 0; } static void From 92bf2d8256a5b87e6de9f7305d26148642b68fd2 Mon Sep 17 00:00:00 2001 From: Maxim <46995666+Vincenz099@users.noreply.github.com> Date: Tue, 7 Apr 2020 12:33:26 +0200 Subject: [PATCH 2/4] Make recvLength = 0; In the rare case of it having bogus data. I noticed from testing this that this might be the source of it, I once had a package returned with length total bogus. like 982349829 or something like that, it crashed my game, I suspect this is the source. --- win32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win32.c b/win32.c index 81175a4..687aa9f 100644 --- a/win32.c +++ b/win32.c @@ -354,7 +354,7 @@ enet_socket_receive (ENetSocket socket, { INT sinLength = sizeof (struct sockaddr_in); DWORD flags = 0, - recvLength; + recvLength = 0; struct sockaddr_in sin; if (WSARecvFrom (socket, From 007b7d2a3f81505f615eda40f6795b95a2208bee Mon Sep 17 00:00:00 2001 From: Maxim <46995666+Vincenz099@users.noreply.github.com> Date: Tue, 7 Apr 2020 12:48:10 +0200 Subject: [PATCH 3/4] Se trecvLength = 0; --- unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix.c b/unix.c index a636f03..acb05c3 100644 --- a/unix.c +++ b/unix.c @@ -475,7 +475,7 @@ enet_socket_receive (ENetSocket socket, { struct msghdr msgHdr; struct sockaddr_in sin; - int recvLength; + int recvLength = 0; memset (& msgHdr, 0, sizeof (struct msghdr)); From 67cee4803a3338f0ee2e049ceac215925b9cd908 Mon Sep 17 00:00:00 2001 From: Maxim <46995666+Vincenz099@users.noreply.github.com> Date: Tue, 7 Apr 2020 13:02:48 +0200 Subject: [PATCH 4/4] Set DWORD sentLength = 0; Same case like receive, we should initialize this variable. --- unix.c | 2 +- win32.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unix.c b/unix.c index acb05c3..a636f03 100644 --- a/unix.c +++ b/unix.c @@ -475,7 +475,7 @@ enet_socket_receive (ENetSocket socket, { struct msghdr msgHdr; struct sockaddr_in sin; - int recvLength = 0; + int recvLength; memset (& msgHdr, 0, sizeof (struct msghdr)); diff --git a/win32.c b/win32.c index 687aa9f..eebdb03 100644 --- a/win32.c +++ b/win32.c @@ -316,7 +316,7 @@ enet_socket_send (ENetSocket socket, size_t bufferCount) { struct sockaddr_in sin; - DWORD sentLength; + DWORD sentLength = 0; if (address != NULL) {