What is causing Tmap to crash the Editor?

For some reason I this function keeps crashing on line 36 with the error “Assertion failed: Pair != NULL”. I’m not using pointers and I suspend the thread that uses PathQueue TMap.

void FPathfindingWorker::AddNewPath(int32 Key, TArray<FVector> Nodes, FVector start, FVector finish)
{
	if (Thread)
	{
		Thread->Suspend(true);
		PathQueue.Add(Key);
		PathQueue[Key].Add("AllNodes");
		PathQueue[Key].Add("OpenList");
		PathQueue[Key].Add("ClosedList");
		PathQueue[Key].Add("PathList");
		for (FVector Entry : Nodes)
		{
			FString HashVector = Entry.ToCompactString();
			NodeData data;
			data.Location = Entry;
			data.bStart = false;
			data.bTarget = false;
			data.bClosed = false;
			data.bOpen = false;
			data.Fx = 0;
			data.Gx = 0;
			data.Hx = 0;
			data.Parent = Entry;
			CompleteList.Add(Key, false);
			if (finish.Equals(Entry))
			{
				data.bTarget = true;
			}
			if (start.Equals(Entry))
			{
				data.bStart = true;
				PathQueue[Key]["ClosedList"].Add(HashVector, data);
			}
			else
			{
				PathQueue[Key]["AllNodes"].Add(HashVector, data); // crash
			}
			if (start.Equals(finish))
			{
				data.bClosed = true;
				PathQueue[Key]["PathList"].Add(HashVector, data);
				ProcessedPaths.Add(Key, PathQueue[Key]);
				PathQueue.Remove(Key);
				CompleteList[Key] = true;

			}
		}
		Thread->Suspend(false);
	}
}

Here is the declaration to PathQueue:

TMap<int32, TMap<FString, TMap<FString, NodeData>>> PathQueue; 

I’m not sure if this is because of thread safety, unreal not supporting TMap inside TMaps, or something else.

I recon this question is 2 years old. However the reason as to why this assertion fails hasn’t changed to date (version 4.13.1 of the engine). It might help a fellow reader.

Anywho, this code simply crashes because one of the pairs the author tries to address here - particularly PathQueue[Key]["PathList"] - does not exist: either Key or "PathList".

Always ensure the pair exists by checking with, in this example, PathQueue.Contains(Key) and PathQueue[Key].Contains(FString(TEXT("PathList"))) (assuming PathQueue is a TMap<..., TMap>.

Cause the function suspend is windows specific and unsafe. you have to enforce the use of it. wrap your code in the following includes and it will work

    #include "AllowWindowsPlatformTypes.h"
    
    // all your code that uses lowlevel threading should be here

    #include "HideWindowsPlatformTypes.h"