DataTable crashes only on standalone mode

Hi everyone,

I am using my own datatables on the game and that works perfectly on PIE mode. Whenever I start standalone game, it cause crashes.

Error is:

Error        LogWindows           Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xfffff21c
Error        LogWindows           
Error        LogWindows           [Callstack] 0x00007ff9a48347d5 UE4Editor-CoreUObject.dll!UnknownFunction []
Error        LogWindows           [Callstack] 0x00007ff9d84b9578 UE4Editor-RTS2-0007.dll!UDataTable::FindRow<FPredefinedGameMode>() [e:\ue\ue_4.24\engine\source\runtime\engine\classes\engine\datatable.h:203]

Code beIow is the way I use to read DataTable,

void DataStore::ReadGameInfoData()
{
	FSoftObjectPath UnitDataTablePath = FSoftObjectPath(TEXT("DataTable'/Game/Data/DefaultGameModes.DefaultGameModes'"));
	DefaultGameModesData = Cast<UDataTable>(UnitDataTablePath.ResolveObject());
	
	if (DefaultGameModesData == nullptr)
	{
		DefaultGameModesData = Cast<UDataTable>(UnitDataTablePath.TryLoad());
	} 
}

ReadGameInfoData function is called from GameInstance::Init function. And following DataStore::GetDefaultGameMode() function is called from GameMode::StartPlay function.

FRTSGameMode* DataStore::GetDefaultGameMode()
{
	LOG_ERR("GetDefaultGameMode ");
	if (DefaultGameModesData == nullptr)
	{
		LOG_ERR("DefaultGameModesData pointer is null");
		ReadGameInfoData();
	}
	
	FPredefinedGameMode* GM = DefaultGameModesData->FindRow<FPredefinedGameMode>("GameInfos", TEXT(""));

	if(GM != nullptr)
	{
		return GetRTSGameModeFromGameInfo(GM->ActiveGameModeIndex);
	}
	ensureMsgf(GM != nullptr, TEXT("GetDefaultGameMode GameModes is null"));
	return nullptr;	
}

Between “DefaultGameModesData pointer is null” log is never printed.

Thanks

A sentence “Objects such as the GameInstance are created and initialized before starting the engine” took my attention at following page UE4 Game Flow

Somehow TryLoad function fails to load datatable, still it assigns the DefaultGameModesData pointer with a value other than nullptr, This could be an engine bug. Just because DefaultGameModesData is not nullptr anymore, I can not reload it.

The solution is below

I was calling DataStore::ReadGameInfoData function (function I load my datatable) from GameInstance::Init function, but Engine is not started at this stage according to documentattion. Then I move calling DataStore::ReadGameInfoData inside GameMode::StartPlay function. Then It worked.

Thank you!!