FString::Replace() crashing somewhere it NEVER crashed before

Dear Friends at Epic,

In 4.2, FString::replace() crashes somewhere that it has NEVER crashed before!

//Time
FString TheCurrentDate = FDateTime::Now().ToString();
TheCurrentDate = TheCurrentDate.Replace(TEXT("."), NULL);  <--- crashes here
TheCurrentDate = TheCurrentDate.Replace(TEXT("-"), NULL);
TheCurrentDate = TheCurrentDate.Replace(TEXT("0"), NULL);

#Crash Log

[2014.06.05-01.56.37:519][ 15]LogWindows: === Critical error: ===
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000

[2014.06.05-01.56.37:519][ 15]LogWindows: Fatal error!

FString::Replace() 0xe01ab123 + 9 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\core\private\containers\string.cpp:824] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Core.dll]
USolusCoreHighest::GenerateUniqueSolusVibe() 0xd708d197 + 32 bytes [File=c:\users\rama\documents\unreal projects\solus\source\solus\soluscore\soluscorehighest.cpp:22] [in C:\Users\Rama\Documents\Unreal Projects\Solus\Binaries\Win64\UE4Editor-Solus.dll]
ASolusItemStaticMesh::BeginPlay() 0xd7082472 + 113 bytes [File=c:\users\rama\documents\unreal projects\solus\source\solus\solusitems\solusitemstaticmesh.cpp:117] [in C:\Users\Rama\Documents\Unreal Projects\Solus\Binaries\Win64\UE4Editor-Solus.dll]
ULevel::RouteActorInitialize() 0xd82b6c9c + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\level.cpp:1623] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UWorld::AddToWorld() 0xd86c1ac7 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\world.cpp:1485] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UWorld::UpdateLevelStreamingInner() 0xd86e944d + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\world.cpp:2044] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UWorld::UpdateLevelStreaming() 0xd86e8e18 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\world.cpp:2117] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UGameViewportClient::Draw() 0xd8168041 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\gameviewportclient.cpp:799] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
USolusViewportClient::Draw() 0xd708894f + 0 bytes [File=c:\users\rama\documents\unreal projects\solus\source\solus\soluspc\solusviewportclient.cpp:94] [in C:\Users\Rama\Documents\Unreal Projects\Solus\Binaries\Win64\UE4Editor-Solus.dll]
FViewport::Draw() 0xd8648487 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\unrealclient.cpp:1071] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UGameEngine::RedrawViewports() 0xd818a041 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\gameengine.cpp:356] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
UGameEngine::Tick() 0xd8195e02 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\engine\private\gameengine.cpp:949] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor-Engine.dll]
FEngineLoop::Tick() 0x3f717b03 + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\launch\private\launchengineloop.cpp:2091] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor.exe]
GuardedMain() 0x3f70d1ec + 0 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\launch\private\launch.cpp:132] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor.exe]
GuardedMainWrapper() 0x3f70d25a + 5 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\launch\private\windows\launchwindows.cpp:125] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor.exe]
WinMain() 0x3f719119 + 17 bytes [File=e:\victoryue4\unrealengine-4.2\engine\source\runtime\launch\private\windows\launchwindows.cpp:207] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor.exe]
__tmainCRTStartup() 0x3f719fa9 + 21 bytes [File=f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618] [in E:\VictoryUE4\UnrealEngine-4.2\Engine\Binaries\Win64\UE4Editor.exe]
Address = 0x76ca652d (filename not found) [in C:\Windows\system32\kernel32.dll]
Address = 0x76edc521 (filename not found) [in C:\Windows\SYSTEM32\ntdll.dll]
Address = 0x76edc521 (filename not found) [in C:\Windows\SYSTEM32\ntdll.dll]

[2014.06.05-01.56.37:520][ 15]LogExit: Executing StaticShutdownAfterError
[2014.06.05-01.56.37:592][ 15]LogWindows: FPlatformMisc::RequestExit(1)
[2014.06.05-01.56.37:592][ 15]Log file closed, 06/04/14 21:56:37

#Workaround Solution

TheCurrentDate = TheCurrentDate.Replace(TEXT("."), NULL);
TheCurrentDate = TheCurrentDate.Replace(TEXT("-"), NULL);
TheCurrentDate = TheCurrentDate.Replace(TEXT("0"), NULL);

has to now become

TheCurrentDate = TheCurrentDate.Replace(TEXT("."), TEXT(""));
TheCurrentDate = TheCurrentDate.Replace(TEXT("-"), TEXT(""));
TheCurrentDate = TheCurrentDate.Replace(TEXT("0"), TEXT(""));

please fix this so I dont have to do this!

I never had to do before!

Rama

#Crash Fix Posted on GitHub

I have given the crash fix to the engine code in string.cpp to Epic on Github

https://github.com/EpicGames/UnrealEngine/pull/208

the new version of FString::Replace was not accounting for whether the To argument was null!

I’ve offered Epic the fix that I’ve implemented in my version of 4.2, that resolves the crash and restores the expected behavior when NULL is passed in.

FString FString::Replace(const TCHAR* From, const TCHAR* To, ESearchCase::Type SearchCase) const
{
	if (IsEmpty() || !From || !*From)
	{
		return *this;
	}

	if(!To)
	{
		To = TEXT("");
	}