My Serialize function is crashing Unreal, only when changing values in editor

So my Serialize function is in a SaveGame object. It has a list of DataTables and when I change the list it crashes unreal with the following error. A lot of code is reused from unreal’s UDataTable. If I uncomment out the return after calling Super::Serialize(Ar), I can modify the list. It needs it to save the TMap I have and works fine once the list is created and saved.

Error:
[Spoiler]


MachineId:577598FB4E52BF0E556056870339D9B0
EpicAccountId:b018f520f319458ca2614a55946634a9

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

UE4Editor_RPG_Project!UMySaveGame::Serialize() [d:\documents\unreal projects\rpg_project\source\rpg_project\private\mysavegame.cpp:118]
UE4Editor_UnrealEd!FTransaction::FObjectRecord::SerializeContents() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\editortransaction.cpp:137]
UE4Editor_UnrealEd!FTransaction::FObjectRecord::FObjectRecord() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\editortransaction.cpp:71]
UE4Editor_UnrealEd!FTransaction::SaveObject() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\editortransaction.cpp:376]
UE4Editor_CoreUObject!SaveToTransactionBuffer() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2150]
UE4Editor_CoreUObject!UObject::Modify() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\obj.cpp:959]
UE4Editor_CoreUObject!UObject::PreEditChange() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\obj.cpp:309]
UE4Editor_PropertyEditor!FPropertyNode::NotifyPreChange() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\propertynode.cpp:2205]
UE4Editor_PropertyEditor!FPropertyValueImpl::ImportText() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:484]
UE4Editor_PropertyEditor!FPropertyValueImpl::ImportText() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:331]
UE4Editor_PropertyEditor!FPropertyValueImpl::SendTextToObjectProperty() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:287]
UE4Editor_PropertyEditor!FPropertyHandleObject::SetValue() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\propertyhandleimpl.cpp:2882]
UE4Editor_PropertyEditor!SPropertyEditorAsset::SetValue() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\userinterface\propertyeditor\spropertyeditorasset.cpp:581]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyEditorAsset,0,TTypeWrapper<void> __cdecl(FAssetData const & __ptr64)>::Execute() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:318]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyEditorAsset,0,void __cdecl(FAssetData const & __ptr64)>::ExecuteIfSafe() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:425]
UE4Editor_PropertyEditor!SPropertyMenuAssetPicker::OnAssetSelected() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\propertyeditor\private\userinterface\propertyeditor\spropertymenuassetpicker.cpp:234]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyMenuAssetPicker,0,TTypeWrapper<void> __cdecl(FAssetData const & __ptr64)>::Execute() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:318]
UE4Editor_PropertyEditor!TBaseSPMethodDelegateInstance<0,SPropertyMenuAssetPicker,0,void __cdecl(FAssetData const & __ptr64)>::ExecuteIfSafe() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:425]
UE4Editor_ContentBrowser!SAssetView::AssetSelectionChanged() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\contentbrowser\private\sassetview.cpp:3522]
UE4Editor_ContentBrowser!TBaseSPMethodDelegateInstance<0,SAssetView,0,TTypeWrapper<void> __cdecl(TSharedPtr<FAssetViewItem,0>,enum ESelectInfo::Type)>::Execute() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:318]
UE4Editor_ContentBrowser!TBaseSPMethodDelegateInstance<0,SAssetView,0,void __cdecl(TSharedPtr<FAssetViewItem,0>,enum ESelectInfo::Type)>::ExecuteIfSafe() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:425]
UE4Editor_ContentBrowser!TBaseDelegate<void,TSharedPtr<FAssetViewItem,0>,enum ESelectInfo::Type>::ExecuteIfBound() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegatesignatureimpl.inl:609]
UE4Editor_ContentBrowser!SListView<TSharedPtr<FAssetViewItem,0> >::Private_SignalSelectionChanged() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\public\widgets\views\slistview.h:638]
UE4Editor_ContentBrowser!STableRow<TSharedPtr<FAssetViewItem,0> >::OnMouseButtonUp() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\public\widgets\views\stablerow.h:449]
UE4Editor_Slate!<lambda_8d0e9a1da76abd0a756a3a9d775f5ed1>::operator()() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:5010]
UE4Editor_Slate!FEventRouter::Route<FReply,FEventRouter::FToLeafmostPolicy,FPointerEvent,<lambda_8d0e9a1da76abd0a756a3a9d775f5ed1> >() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:215]
UE4Editor_Slate!FSlateApplication::RoutePointerUpEvent() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:4999]
UE4Editor_Slate!FSlateApplication::ProcessMouseButtonUpEvent() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:5462]
UE4Editor_Slate!FSlateApplication::OnMouseUp() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\slate\private\framework\application\slateapplication.cpp:5439]
UE4Editor_Core!FWindowsApplication::ProcessDeferredMessage() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsapplication.cpp:1652]
UE4Editor_Core!FWindowsApplication::DeferMessage() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsapplication.cpp:2071]
UE4Editor_Core!FWindowsApplication::ProcessMessage() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsapplication.cpp:814]
UE4Editor_Core!FWindowsApplication::AppWndProc() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsapplication.cpp:678]
user32
user32
UE4Editor_Core!FWindowsPlatformMisc::PumpMessages() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\windows\windowsplatformmisc.cpp:951]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2811]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launch.cpp:152]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

[/Spoiler]

.h
[Spoiler]



UPROPERTY(EditDefaultsOnly, Category = "Default")
	TArray<UDataTable*> DataTables;

TMap<int32, TMap<FName, uint8*>> DataStructs;

...

virtual void Serialize(FArchive& Ar) override;

...


[/Spoiler]

.cpp
[Spoiler]




void UMySaveGame::Serialize(FArchive& Ar) {
	Super::Serialize(Ar);
	//return;
	if (Ar.IsSaving()) {
		for (int32 i = 0; i < DataTables.Num(); i++) {
			UScriptStruct* SaveUsingStruct = DataTables*->RowStruct;
			
			int32 NumRows = DataStructs*.Num();
			Ar << NumRows;

			// Now iterate over rows in the map
			for (auto RowIt = DataStructs*.CreateIterator(); RowIt; ++RowIt)
			{
				// Save out name
				FName RowName = RowIt.Key();
				Ar << RowName;

				// Save out data
				uint8* RowData = RowIt.Value();

				SaveUsingStruct->SerializeItem(Ar, RowData, nullptr);
			}
		}
	}
	else if (Ar.IsLoading()) {
		ClearAllData();
		for (int32 i = 0; i < DataTables.Num(); i++) {
			UScriptStruct* LoadUsingStruct = DataTables*->RowStruct;

			int32 NumRows;
			Ar << NumRows;

			for (int32 RowIdx = 0; RowIdx < NumRows; RowIdx++)
			{
				// Load row name
				FName RowName;
				Ar << RowName;

				// Load row data
				uint8* RowData = (uint8*)FMemory::Malloc(LoadUsingStruct->GetStructureSize());

				// And be sure to call DestroyScriptStruct later
				LoadUsingStruct->InitializeStruct(RowData);

				LoadUsingStruct->SerializeItem(Ar, RowData, nullptr);

				// Add to map
				DataStructs*.Add(RowName, RowData);
			}
		}
	}
}

[/Spoiler]

it seems you are trying to read some null at line 118, either way, you dont need override the Serialize function, all you need to do is create a FMemoryWriter or FMemoryReader, add your TArray, Serialize and process your info

Where would I put the FMemoryWriter or FMemoryReader without Serialize()? The reason I’m using it now is because I want it to work with unreal’s Save/Load system right now.

Hi LazyLoading,

In whatever static function you want, see how they are implemented in UGameStatics, those functions are the basic for save game info, check for:



/**
	 * see UGameplayStatics::CreateSaveGameObject
	 * see UGameplayStatics::SaveGameToSlot
	 * see UGameplayStatics::DoesSaveGameExist
	 * see UGameplayStatics::LoadGameFromSlot
	 * see UGameplayStatics::DeleteGameInSlot
	 */