Why is StaticMesh SetVisibility method causing UE4 to crash?

Can someone please help to explain the following behavior to me? I’m a career Java developer, so I understand that this question may be hopelessly naive.

When I pass a “fixed” boolean argument into the SetVisibility method of a StaticMesh object, it behaves as documented. However, when I subject the argument to conditional logic, it causes the program to crash. Why is this?

/* This works! */
//This is a UStaticMeshObject pointer to an initialized UStaticMeshComponent
XVox[x].YVox[y].ZVox[z].BVox = PCIP.CreateAbstractDefaultSubobject<UStaticMeshComponent>(this, TFNameFString);
XVox[x].YVox[y].ZVox[z].BVox->SetVisibility(true);

/* This also works! */
bool IsVoxelVisible = true;
XVox[x].YVox[y].ZVox[z].BVox->SetVisibility(IsVoxelVisible);

/* This also works! */
bool IsVoxelVisible = false;
XVox[x].YVox[y].ZVox[z].BVox->SetVisibility(IsVoxelVisible);

/* This causes the UE4 editor to crash when opening the project :( */
bool IsVoxelVisible = (vol[x][y][z] > 0);
XVox[x].YVox[y].ZVox[z].BVox->SetVisibility(IsVoxelVisible);

/* This also causes the UE4 editor to crash */
bool IsVoxelVisible = false;
if(vol[x][y][z] > 0) IsVoxelVisible = true;
XVox[x].YVox[y].ZVox[z].BVox->SetVisibility(IsVoxelVisible);

Hi there! From the code you’ve posted, the only thing that is different between the code that crashes and the code that doesn’t, is the following 3D array access:

vol[x][y][z]

I can only assume that the array is not big enough and you’re getting an array out of bounds exception or similar. Could you please verify that ‘vol’ is indeed large enough to account for the x/y/z indices you are supplying?

Right on the money, the cause of the issue was a problem with my array access, and not a behavior of the StaticMeshComponent.

Great! Thanks for letting us know.