Debug Assertion Failed Error

Hi @Jeremy_Thompson, sorry for taking ages to reply. Try using Guess[j] in the comparison - I think that’s where you get out of range.

Apparently, I’ve posted similiar issue as out of bounds error when running the console. Just to let you know, none of the above solutions work for me. It keeps giving error on a specific line of code (42 in my case) which looks like:

int32 HiddenWordLength = MyHiddenWord.length();

Hey, having same problem…

Only occurs when I use a one letter word.

Would appreciate the help.

What does your main.cpp look like?

Do you know which video he explains this in? Is it in section 2 cuz i finished section 2 and didn’t see the soIution. I don’t want to start section 3 without having it all working unless that’s where he explains it.

“Writing Error Checking Code” as we check to make sure the guess is valid before going to that function. The problem as described in the OP happens because the guess is shorter than the hidden word so the for loop goes out of bounds

Guess = “ant”;
HiddenWord = “planet”;

The loop will go for HiddenWord.length() times so

GCHar = ‘a’, HiddenWord = 'p’
GChar = ‘n’, HiddenWord = 'p’
GCHar = ‘t’, HiddenWord = 'p’
GCHar = ‘\0’, HiddenWord = 'p’
GCHar = ???, HiddenWord = ‘p’ <- Error happens here.
GCHar = ???, HiddenWord = ‘p’

That’s not the error I’m getting. It works when I put in less letters or more letters or uppercase or anything with the enum besides when I get 5 letters. So if the hidden word is 5 letters and I put in 5 letters (regardless of how many bulls or cows) then I get the error. I posted my source code here - Debug Assertion Failed . Any idea what I did wrong?

Ive been continually getting this error and it seems nothing i try works. I know it has to do with the subscripts being out of range i just cant figure out why.

Why doesnt this code here https://gist.github.com/anonymous/3db78aa7e80d8f5ce50d3a3eea3bf527
fix the problem?

its only an issue if i type in a single character. if i type in 2 it works. im assuming its because [i] == [0], not sure how 0 can be out of range for an index. could [i] == [-1] ???

any help would be nice.

follow up to my question, why does the instructors solution here https://gist.github.com/anonymous/ace331742c25e95e23c8987e555994b0
work but every other solution causes that error? Id like to understand this before moving on if possible.

I must say this is not quite the correct solution. This code only works when the hidden word and the guessed word have the same length, otherwise it may or may not cause an issue. e.g. it will cause an assertion failure when your hidden word has 5 letters and you try a guess with a 3-letter word.
The problem is this code assumes that Guess.length() == MyHiddenWord.length() always! So instead of using MyHiddenWordLength in both for loops, you use Guess.length() in the first loop, and as a result use the appropriate index (j) for the MyHiddenWord. See this corrected version:

FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
	//increment turn number
	MyCurrentTry++;

	//setup a return variable
	FBullCowCount BullCowCount;
	int32 HiddenWordLength = MyHiddenWord.length();
	for (int32 i = 0; i < Guess.length(); i++)
	{
		for (int32 j = 0; j <= HiddenWordLength - 1; j++)
		{
			if (TheGuess[i] == MyHiddenWord[j])
			{
				if (i == j)
				{
					BULL_COW_COUNT.Bulls++;
				}
				else
				{
					BULL_COW_COUNT.Cows++;
				}
			}
		}
		return BULL_COW_COUNT;
	}
}
1 Like

Thank you for clarifying this to me. It makes more sense now. I really appreciate the help and prompt reply. Ill keep that in mind going forward. :grin:

I’m infuriated at the authors of this course. I still can’t fix this error even with the solutions given here. One of the solutions that averts the error disrupts the functionality of the game.

The authors are off making other courses that they can sell and apparently are fine completely abandoning their students and not providing an answer to this that is clear and correct. If I don’t get an appropriate answer to this question by the time I finish this course I’m giving it negative stars if possible. Shame on the people who made this for putting the burden on their students and not looking into this and offering the solution.

This solution doesn’t even work.

How am I supposed to follow the rest of this course if I can’t even compile this?

if you could share your code here that would be useful

Hi OldDauber,

Thanks for the note. I reverted back to the course code after your snippet wasn’t working, so here it is as it stands now:

FBullCowCount FBullCowGame::SubmitGuess(FString Guess)
{
	// incriment the turn number
	MyCurrentTry++;

	// setup a return variable
	FBullCowCount BullCowCount;

	// loop through all letters in the guess
	int32 HiddenWordLength = MyHiddenWord.length();
	for (int32 MHWChar = 0; MHWChar < HiddenWordLength; MHWChar++) {
		// compare letters against the hidden word
		for (int32 GChar = 0; GChar < HiddenWordLength; GChar++) {
			// if they match then
			if (Guess[GChar] == MyHiddenWord[MHWChar]) {
				if (MHWChar == GChar) { // if they're in the same place
					BullCowCount.Bulls++; // incriment bulls
				}
				else {
					BullCowCount.Cows++; // must be a cow
				}
			}
		}
	}
	return BullCowCount;
}

I think it’s worth mentioning for anyone else that may be thinking about taking lessons with these people that I actually needed to spell-correct this code even though I took it directly from the lesson snippet on Github. Just one of numerous, numerous mispellings and mistakes which litter the slides and code from what is turning out to be the sloppiest and worst course on Udemy I have ever taken. Length was spelled incorrectly for probably the tenth time since I’ve started the course - the supposedly native english speakers who give it cannot spell the words “Increment”, “Hidden”, “Length” and various other words that any 10 year old of average intelligence can spell and type.

That being said - using the code above crashes in the same manner when I attempt to type in a three letter word.

I’d appreciate any help that can be offered, but I’d appreciate even more an explanation from the authors on why they have offered no solution for this and why they are still silent on this thread that is over twenty posts long, and then offer an answer that actually works.

For anyone else with this issue see here:

James_C,
The code snippet I posted here works just fine. It didn’t work for you because you had NOT copied it correctly (referring to your stackoverflow post)

It didn’t work at all. The post I made at Stack was after other alterations I had made after I discovered your attempt did not work.

Privacy & Terms