Crash when returning nullptr for function

anonymous_user_d251ba76
Thu, 17 Nov 2016 06:24:47 +0000
Editor Scripting

When returning nullptr my UE4 crashes. I’m trying to make a saving function and when the save text is nothing it checks whether it is valid and then returns the nullptr value instead of the cast. How is returning null meant to be done in c++? I think my practices are different because my main language before c++ was Java. Here is what some of the code looks like in my .cpp:

USG_Evolution* UCFunctionLibrary::SGUserSave(FString SaveName, FString& SaveNameReturn)
{
	SaveNameReturn = SaveName;
	TSubclassOf<USG_Evolution> Class;
	USG_Evolution* SaveGameInstance = Cast<USG_Evolution>(SGBase(Class, SaveName, SaveNameReturn));
	if (SaveGameInstance->IsValidLowLevel())
	{
		return SaveGameInstance;
	}
	else
	{
		UE_LOG(LogTemp, Log, TEXT("SGUserSave Failed"));
		return nullptr;
	}
}

So if the SaveGameInstance is valid it returns, otherwise it returns nullptr.

3 posts - 1 participant