Since upgradiing to 2017.1.xxxx we started seeing a number of crashes in the editor (could happen in game too!) on level swap. It wasn't terribly common but I root caused it to the fact that "GetWorld" for a component in UE4 can return null when swapping levels. (I.E. the world can be in-accessible during level swap).
Apologies in advance for the formatting. I don't see support for code blocks here.
The crash would occur in this function, but that's not the best place to fix it:
template<class COMPONENT_TYPE>
void FAkAudioDevice::RemovePrioritizedComponentFromList(COMPONENT_TYPE* in_ComponentToRemove, TMap<UWorld*, COMPONENT_TYPE*>& HighestPriorityComponentMap)
The fix is pretty simple. Add this to FAkAudioDevice::Init
// OnWorldCleanupDelegateHandle is a new member variable I declared in FAkAudioDevice
OnWorldCleanupDelegateHandle = FWorldDelegates::OnWorldCleanup.AddLambda(
[&](UWorld* WorldBeingCleanedup, bool, bool)
{
HighestPriorityLateReverbComponentMap.Remove(WorldBeingCleanedup);
HighestPriorityRoomComponentMap.Remove(WorldBeingCleanedup);
}
);
and add this line to tear down
FWorldDelegates::OnWorldCleanup.Remove(OnWorldCleanupDelegateHandle);