Fetal Error : ran out of memory allocating

Hello,

I have use RamaUDPReceiver and use the BPEvent_DataReceived(Data); in the GameThread when the data is receive UE4 is crash

I spawn Actor from class(UDPReceiver) in the widget blueprint and do anything in that blue print use the event dispatcher for call DataReceived event

Is something wrong?

This is crash log

Fatal error: [File:D:\Build\++UE4+Release-4.16+Compile\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMemory.cpp] [Line: 174] 
Ran out of memory allocating 18446744071839558400 bytes with alignment 0


UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:349]
UE4Editor_Core!FGenericPlatformMemory::OnOutOfMemory() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\genericplatform\genericplatformmemory.cpp:175]
UE4Editor_Core!FMallocTBB::Realloc() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\hal\malloctbb.cpp:117]
UE4Editor_Core!TArray<wchar_t,FDefaultAllocator>::ResizeForCopy() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\containers\array.h:2299]
UE4Editor_Core!TArray<wchar_t,FDefaultAllocator>::operator=() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\containers\array.h:419]
UE4Editor_Core!FString::operator=() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\containers\unrealstring.h:1731]
UE4Editor_MasterServer_1679!FPlayerData::operator=()
UE4Editor_MasterServer_1679!ARamaUDPReceiver::BPEvent_DataReceived()
UE4Editor_Core!TGraphTask<FAsyncGraphTask>::ExecuteTask() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:884]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:954]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:701]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1809]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:538]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:1450]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:758]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1380]
UE4Editor_UMGEditor!FWidgetBlueprintEditor::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\umgeditor\private\widgetblueprinteditor.cpp:450]
UE4Editor_UnrealEd!FTickableEditorObject::TickObjects() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\unrealed\public\tickableeditorobject.h:21]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1400]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:386]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3119]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

Thanks

I think that you’re running out of memory, or better say committed memory. I’d bet you 're running windows 10 and most probably your memory is DDR4.

Edit: Shut down UE4 and compile again. The error should go away.

my memory is 16GB DDR3 and my window is window 10

shutdown recompile doesn’t fix it. still crash when receive the data

Thanks

Hard to say what’s wrong from that log. Just a quick guess after taking a better look at it though:
Are you using UPROPERTY() before declaring component variables?

I usually got this error on network due to Integer Overflow, in your case it might be an Int64 overflow, if you are using it to instantiate any array try check its size before. you might sending some Int64 to instantiate which value is -1, but the compiler is reading it as UInt64 which is like 18446744073709551615.

here, take a look at the max values:

I have change int to int32, but when receive data it’s still crash.

this is error that I get.

Access violation - code c0000005 (first/second chance not available)

VCRUNTIME140
UE4Editor_Core!TArray<wchar_t,FDefaultAllocator>::operator=() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\containers\array.h:419]
UE4Editor_Core!FString::operator=() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\containers\unrealstring.h:1731]
UE4Editor_MasterServer_1286!FPlayerData::operator=()
UE4Editor_MasterServer_1286!ARamaUDPReceiver::BPEvent_DataReceived()
UE4Editor_Core!TGraphTask<FAsyncGraphTask>::ExecuteTask() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:884]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:954]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:701]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\core\private\async\taskgraph.cpp:1809]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:538]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\ticktaskmanager.cpp:1450]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:758]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1373]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1633]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:386]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3119]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [d:\build\++ue4+release-4.16+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

There is a chance for us to see a piece of that code?

UDPSender.cpp
/*

RamaUDPSender

by Rama
*/
#include "RamaUDPSender.h"
//#include "UDPSendReceive.h"
#include "PlayerData.h"


ARamaUDPSender::ARamaUDPSender(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	SenderSocket = NULL;

	ShowOnScreenDebugMessages = true;
}

void ARamaUDPSender::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);
	//~~~~~~~~~~~~~~~~

	if (SenderSocket)
	{
		SenderSocket->Close();
		ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(SenderSocket);
	}
}

bool ARamaUDPSender::StartUDPSender(
	const FString& YourChosenSocketName,
	const FString& TheIP,
	const int32 ThePort,
	bool UDP
) {
	//Create Remote Address.
	RemoteAddr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->CreateInternetAddr();

	bool bIsValid;
	RemoteAddr->SetIp(*TheIP, bIsValid);
	RemoteAddr->SetPort(ThePort);

	if (!bIsValid)
	{
		ScreenMsg("Rama UDP Sender>> IP address was not valid!", TheIP);
		return false;
	}

	SenderSocket = FUdpSocketBuilder(*YourChosenSocketName)
		.AsReusable()
		.WithBroadcast()
		;


	//check(SenderSocket->GetSocketType() == SOCKTYPE_Datagram);

	//Set Send Buffer Size
	int32 SendSize = 2 * 1024 * 1024;
	SenderSocket->SetSendBufferSize(SendSize, SendSize);
	SenderSocket->SetReceiveBufferSize(SendSize, SendSize);

	ScreenMsg("Rama ****UDP**** Sender Initialized Successfully!!!");
	UE_LOG(LogTemp, Log, TEXT("\n\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
	UE_LOG(LogTemp, Log, TEXT("Rama ****UDP**** Sender Initialized Successfully!!!"));
	UE_LOG(LogTemp, Log, TEXT("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n\n"));

	return true;
}

bool ARamaUDPSender::RamaUDPSender_SendString(FString pIP,FString pID,FString pCommand,FString pPort)
{
	if (!SenderSocket)
	{
		ScreenMsg("No sender socket");
		return false;
	}
	//~~~~~~~~~~~~~~~~

	int32 BytesSent = 0;

	FPlayerData pData;
	pData.PlayerIP = pIP;
	pData.PlayerID = pID;
	pData.PlayerCommand = pCommand;
	pData.PlayerPort = pPort;

	FArrayWriter Writer;

	Writer << pData; //Serializing our custom data, thank you UE4!

	SenderSocket->SendTo(Writer.GetData(), Writer.Num(), BytesSent, *RemoteAddr);

	if (BytesSent <= 0)
	{
		const FString Str = "Socket is valid but the receiver received 0 bytes, make sure it is listening properly!";
		UE_LOG(LogTemp, Error, TEXT("%s"), *Str);
		ScreenMsg(Str);
		return false;
	}

	ScreenMsg("UDP~ Send Succcess! Bytes Sent = ", BytesSent);

	return true;
}

UDPReceiver.cpp
/*

RamaUDPReceiver

by Rama
*/
//#include "UDPSendReceive.h"
#include "RamaUDPReceiver.h"
#include "PlayerData.h"
#include "Async.h"

ARamaUDPReceiver::ARamaUDPReceiver(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	ListenSocket = NULL;
}

void ARamaUDPReceiver::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	Super::EndPlay(EndPlayReason);
	//~~~~~~~~~~~~~~~~
	UDPReceiver->Stop();
	delete UDPReceiver;
	UDPReceiver = nullptr;

	//Clear all sockets!
	//		makes sure repeat plays in Editor dont hold on to old sockets!
	if (ListenSocket)
	{
		ListenSocket->Close();
		ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(ListenSocket);
	}
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//Rama's Start TCP Receiver
bool ARamaUDPReceiver::StartUDPReceiver(
	const FString& YourChosenSocketName,
	const FString& TheIP,
	const int32 ThePort
) {

	ScreenMsg("RECEIVER INIT");

	//~~~

	FIPv4Address Addr;
	FIPv4Address::Parse(TheIP, Addr);

	//Create Socket
	FIPv4Endpoint Endpoint(Addr, ThePort);

	//BUFFER SIZE
	int32 BufferSize = 2 * 1024 * 1024;

	ListenSocket = FUdpSocketBuilder(*YourChosenSocketName)
		.AsNonBlocking()
		.AsReusable()
		.BoundToEndpoint(Endpoint)
		.WithReceiveBufferSize(BufferSize);
	;

	FTimespan ThreadWaitTime = FTimespan::FromMilliseconds(100);
	UDPReceiver = new FUdpSocketReceiver(ListenSocket, ThreadWaitTime, TEXT("UDP RECEIVER"));
	UDPReceiver->OnDataReceived().BindUObject(this, &ARamaUDPReceiver::Recv);
	UDPReceiver->Start();

	return true;
}

void ARamaUDPReceiver::Recv(const FArrayReaderPtr& ArrayReaderPtr, const FIPv4Endpoint& EndPt)
{
	ScreenMsg("Received bytes", ArrayReaderPtr->Num());

	FPlayerData Data;
	*ArrayReaderPtr << Data;		//Now de-serializing! See AnyCustomData.h

									//BP Event

	
	AsyncTask(ENamedThreads::GameThread, [&]() {
		BPEvent_DataReceived(Data); // call your event this way so it'll be executed on game thread
	});
	//BPEvent_DataReceived(Data);
}

The FPlayerData seems to be your custom data, can we take a look on it?

PlayerData

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "PlayerData.generated.h"

USTRUCT(BlueprintType)
struct FPlayerData
{
	GENERATED_USTRUCT_BODY()

		UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerData")
		FString PlayerIP = "127.0.0.1";
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerData")
		FString PlayerID = "100000";
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerData")
		FString PlayerCommand = "CreateLobby";
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PlayerData")
		FString PlayerPort = "7777";

	

	FPlayerData()
	{}
};

FORCEINLINE FArchive& operator<<(FArchive &Ar, FPlayerData& TheStruct)
{
	Ar << TheStruct.PlayerIP;
	Ar << TheStruct.PlayerID;
	Ar << TheStruct.PlayerCommand;
	Ar << TheStruct.PlayerPort;

	return Ar;
}

just as test, can you comment the lines from 29 to 32…if it doesn’t generate any error, can you try to uncomment one by one?

comment all lines still crash

Can you see the “Recieved bytes” message on screen?
if so, how much is it marking? Try to compare it with the size of the FPlayerData

47 bytes …

is this the sizeof(FPlayerData)?

FPlayerData is 64

First, sorry for taking too long to respond you…

Anyway, it seems you are not recieving a FPlayerData and you are trying to alocate it as a FPlayerData, which might result in some crashes.

just try to print de results as basic chars just to check if these are the data you were looking for.