Array out of bounds in packaged game, works in editor fine.

Hello,

I think the title sums it up but here is the issue that I am having.

this code works fine in the editor:


void UMovesContainer::ConstructMoveFromContainer(class ALevelGamemode* GameMode)
{
	if (ContainerType != EContainerType::ECT_MoveFrom || !GameMode)
		return;

	ContainerSize = GameMode->GetNumMoveOptions();

	if (PieceContatinerClass)
	{
		for (int32 i = 0; i < ContainerSize; i++)
		{
			USinglePieceContainer* CurrContainer = CreateWidget<USinglePieceContainer>(this, PieceContatinerClass);
			MovesPanelBox->AddChild(CurrContainer);
			CurrContainer->HoldPiece(GameMode->GetStartingPieces()[i]);
		}
	}
}

however, when I package the game I get this error:

[2023.04.18-04.43.37:997][239]LogWindows: Error: Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:C:\InstalledApps\Epic

Games\UE_5.1\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 763]
[2023.04.18-04.43.37:997][239]LogWindows: Error: Array index out of bounds: 0 from an array of size 0

[2023.04.18-04.43.37:997][239]LogWindows: Error: [Callstack] 0x00007ff6761675d8 ThinkAhead.exe!UMovesContainer::ConstructMoveFromContainer() [D:\UnrealEngine\ThinkAhead\Source\ThinkAhead\Widget\Move\MovesContainer.cpp:79]

Line 79 is CurrContainer->HoldPiece(GameMode->GetStartingPieces()[i]);

I am unsure how to see the call stack outside of the editor, so I am not sure how to handle this. I know someone probably can’t just tell me the issue, but If someone knows how to go about at least troubleshooting the packaged game, I would appreciate some advice.

Have you tried running it in editor with the console log open? I think you’ll find the error is there, it just doesn’t complain as much…

yeah i did, nothing there unfortunetly, no errors and it all looks normal. I watch the array during development with break points and its never null, so I am unsure of what is going on.

1 Like

You need to open the dmp file in visual studio. For that you will require the debug symbols in the editor. I dont have any file at hand but it should be in the build folder save->crashes (same as with the editor)

When drag into visual you will see on the right the Actions section, there select DebugWithNativeOnly and you should be able to get the callstack.

Hey thanks! I found the issue lookig at the stack. It seems like in editor my “CreateGamePieces” function that populates the array is being called before the function that is using the array, but in the packaged game that order is changing. Strange, but now I can find a work around.