Skip to content

Commit

Permalink
Com crash prevention
Browse files Browse the repository at this point in the history
Added null check
  • Loading branch information
sammyfreg committed Nov 18, 2024
1 parent ab9d516 commit b669823
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Code/Client/Private/NetImgui_NetworkUE4.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "NetImgui_Shared.h"

// Tested with Unreal Engine 4.27, 5.0, 5.2, 5.3, 5.4
// Tested with Unreal Engine 4.27, 5.3, 5.4, 5.5

#if NETIMGUI_ENABLED && defined(__UNREAL__)

Expand All @@ -14,7 +14,7 @@
#include "IPAddressAsyncResolve.h"
#endif

namespace NetImgui { namespace Internal { namespace Network
namespace NetImgui { namespace Internal { namespace Network
{

//=================================================================================================
Expand Down Expand Up @@ -155,14 +155,16 @@ bool DataReceivePending(SocketInfo* pClientSocket)
{
// Note: return true on a connection error, to exit code looping on the data wait. Will handle error after DataReceive()
uint32 PendingDataSize;
return pClientSocket->mpSocket->HasPendingData(PendingDataSize) || (pClientSocket->mpSocket->GetConnectionState() != ESocketConnectionState::SCS_Connected);
return !pClientSocket || pClientSocket->mpSocket->HasPendingData(PendingDataSize) || (pClientSocket->mpSocket->GetConnectionState() != ESocketConnectionState::SCS_Connected);
}

//=================================================================================================
// Block until all requested data has been received from the remote connection
//=================================================================================================
bool DataReceive(SocketInfo* pClientSocket, void* pDataIn, size_t Size)
{
if( !pClientSocket ) return false;

int32 totalRcv(0), sizeRcv(0);
while( totalRcv < static_cast<int>(Size) )
{
Expand All @@ -187,6 +189,8 @@ bool DataReceive(SocketInfo* pClientSocket, void* pDataIn, size_t Size)
//=================================================================================================
bool DataSend(SocketInfo* pClientSocket, void* pDataOut, size_t Size)
{
if( !pClientSocket ) return false;

int32 totalSent(0), sizeSent(0);
while( totalSent < static_cast<int>(Size) )
{
Expand Down
6 changes: 5 additions & 1 deletion Code/Client/Private/NetImgui_NetworkWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ bool DataReceivePending(SocketInfo* pClientSocket)
char Unused[4];
int resultRcv = recv(pClientSocket->mSocket, Unused, 1, MSG_PEEK);
// Note: return true on a connection error, to exit code looping on the data wait
return resultRcv > 0 || (resultRcv == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK);
return !pClientSocket || resultRcv > 0 || (resultRcv == SOCKET_ERROR && WSAGetLastError() != WSAEWOULDBLOCK);
}

//=================================================================================================
// Block until all requested data has been received from the remote connection
//=================================================================================================
bool DataReceive(SocketInfo* pClientSocket, void* pDataIn, size_t Size)
{
if( !pClientSocket ) return false;

int totalRcv(0);
while( totalRcv < static_cast<int>(Size) )
{
Expand All @@ -207,6 +209,8 @@ bool DataReceive(SocketInfo* pClientSocket, void* pDataIn, size_t Size)
//=================================================================================================
bool DataSend(SocketInfo* pClientSocket, void* pDataOut, size_t Size)
{
if( !pClientSocket ) return false;

int totalSent(0);
while( totalSent < static_cast<int>(Size) )
{
Expand Down

0 comments on commit b669823

Please sign in to comment.