子线程中创建Actor导致程序崩溃

void ABP_LevelGameMode::BeginPlay()
{
Super::BeginPlay();

MyWorld = GetWorld();

if (MyWorld)
{
	TFuture<void> Future1 = Async(EAsyncExecution::Thread, [&]() {

		MyWorld->SpawnActor<AMyEntiyBase>(FVector(0, 0, 0), FRotator(0, 0, 0));

		int MsgLen = sizeof(AllEntityInfo);

		SOCKET sockSrv = socket(AF_INET, SOCK_DGRAM, 0);

		SOCKADDR_IN addrSrv;     
		std::string ip = "192.168.1.115";
		addrSrv.sin_addr.S_un.S_addr = inet_addr(ip.c_str());
		addrSrv.sin_family = AF_INET;
		addrSrv.sin_port = htons(6001);

		bind(sockSrv, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));

		SOCKADDR_IN addrClient;  

		char* recvBuf = (char*)malloc(MsgLen);
		AllEntityInfo* data = (AllEntityInfo*)malloc(MsgLen);

		int msgLen = 0;

		while (1)
		{
			msgLen = recvfrom(sockSrv, recvBuf, MsgLen, 0, (SOCKADDR*)&addrClient, &SOCKADDRLEN);

			if (msgLen > 0)
			{
				memcpy(data, recvBuf, MsgLen);
			
				if (MyWorld)
				{				
					MyWorld->SpawnActor<AMyEntiyBase>(AMyEntiyBase::StaticClass(), FVector(0, 0, 0), FRotator(0, 0, 0));
					UE_LOG(LogTemp, Log, TEXT("%d"), data->m_AllEntityInfo[0].ID);
				}
			}
		}
	});
}

}

MyWorld->SpawnActor(AMyEntiyBase::StaticClass(), FVector(0, 0, 0), FRotator(0, 0, 0)); 这行代码导致程序崩溃,除此之外的线程接收udp数据,测试没有问题

异步后对象可能失效了,包括 this,尽可能在回调里面去获取对象,需要传参的不要用引用,用弱指针包一下再传,不然回调内可能会是野指针,没法检查出来的。