Why my editor is crashing from this code?

Hello guys, I’m trying to do a turn based game and i found a way to change turn between the players, but i have a problem.

If i try to run this code:

int i = 0;
while (numActors != 0)
{

	if (apelare)
	{
		apelare = false;
		Jucator = jucatori[i];
		i++;

		Controller = Cast<APawnController>(Jucator->GetController());

		if (Controller != NULL)
		{
			Controller->SetTura_Mea(true);
			()->GetTimerManager().SetTimer(TurnTimer, this, &ARISKGameModeBase::MinusCounter, 1.0f, true);
		}

		else
		{
			AIController = Cast<AAIControllerPawn>(Jucator->GetController());

			AIController->SetTura_Mea(true);
			()->GetTimerManager().SetTimer(TurnTimer, this, &ARISKGameModeBase::MinusCounter, 1.0f, true);
		}

		if (i == numActors)
		{
			i = 0;
		}

	}
}

void ARISKGameModeBase::MinusCounter()
{
	Counter--;

	if (Counter == 0)
	{
		apelare = true;
		Counter = 10;
		GetWorldTimerManager().ClearTimer(TurnTimer);

		AIController = Cast<AAIControllerPawn>(Jucator->GetController());

		if (AIController != nullptr)
		{
			AIController->SetTura_Mea(false);
		}

		else
		{
			Controller = Cast<APawnController>(Jucator->GetController());
			Controller->SetTura_Mea(false);
		}
	}
}

I’ll explain what i’m trying to do with this:

While there are still ‘players’ in game

If i didnt call the ‘MinusCounter’ function(apelare is true

I make "apelare "false

I pick a player

I see if his controller is playercontroller or aicontroller

After i find his controller i set a bool on that controller so i know it’s his turn

After that i start a timer that is meant to be the turn timer

At the end of the timer i set the bool on false so i know it’s not his turn anymore and i set apelare to true

I pick the next player

Why is this crashing? Any ideas?

Without any logs, potential crash points are either line 23 or line 55 as you didn’t protect them in case of nullptr in case cast would fail.

For more you need to show the logs from Saved/Logs, if crash was not asset fail then it will print out error there. Every crash you should look there as you will find useful information, also you can debug to see the stack. If crash is caused by nullptr call you gonna get either cutoff logs or Access Violation

I protected them in case of nullptr at line 23 and 55 and stiil my editor is freezing without response. (not responding )

then it’s because your have an infinite loop :
if you start the loop or end up at the top level of the loop with apelare=false and numActors!=0 => infini loop meaning freeze editor