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:

while (numActors != 0)
{

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

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

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

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

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

	}
}

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?

From this code snippet, I do not see anything that sets “i” to zero to start.

I also don’t see any code that prevents “i” from going out of range on jucatori[i] - does it not need to loop back to zero at some point when you have cycled through all of the players?