Hi all.
I previously worked through the old Bull Cow game where Ben did it in Visual Studio rather than creating a UE4 project around it. I leaned on my old code (probably Ben’s old code) where I used a map rather than the nested for loops and tried to implement it in this project, where I got a nullptr
error. Does anyone have any idea why this code would be throwing an error?
First of all, the old code used a line to reference maps as TMaps. I imagine this may be part of the issue, but I thought they worked the same in UE4.
#define TMap std::map
The code I tried to implement that threw the error was this:
bool UBullCowCartridge::IsIsogram(const FString& Guess) const
{
if (Guess.IsEmpty()) // Line 146
{
PrintLine("Oops. Something went wrong... try again!");
return false;
}
TMap<char, bool> LettersSeen = TMap<char, bool>(); // Line 152
for (int32 index = 0; index < Guess.Len(); index++) // Line 154
{
if (LettersSeen[Guess[index]]) // Line 156 <-- This is where the nullptr is being thrown
{
// Duplicate letter
return false;
}
else
{
LettersSeen[Guess[index]] = true;
}
}
return true; // Line 167
}
The crash reporter is giving me the following traceback:
Assertion failed: Pair != nullptr [File:C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Core\Public\Containers/Map.h] [Line: 621]
UE4Editor_Core
UE4Editor_Core
UE4Editor_BullCowGame_1722!UBullCowCartridge::IsIsogram() [C:\Users\Casey\Documents\GitHub\Bulls-And-Cows-Game\Source\BullCowGame\BullCowCartridge.cpp:156]
UE4Editor_BullCowGame_1722!UBullCowCartridge::OnInput() [C:\Users\Casey\Documents\GitHub\Bulls-And-Cows-Game\Source\BullCowGame\BullCowCartridge.cpp:83]
UE4Editor_BullCowGame_1722!UTerminal::AcceptInputLine() [C:\Users\Casey\Documents\GitHub\Bulls-And-Cows-Game\Source\BullCowGame\Console\Terminal.cpp:143]
UE4Editor_BullCowGame_1722!UTerminal::OnKeyDown() [C:\Users\Casey\Documents\GitHub\Bulls-And-Cows-Game\Source\BullCowGame\Console\Terminal.cpp:112]
UE4Editor_BullCowGame_1722!TBaseUObjectMethodDelegateInstance<0,UTerminal,void __cdecl(FKey),FDefaultDelegateUserPolicy>::Execute() [C:\Program Files\Epic Games\UE_4.26\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:593]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll
Any help on this issue is greatly appreciated!
EDIT 1: Added line numbers in various parts of the code blurb.