Crash sometimes occurs when retrieving a pointer from a TArray

artboy77
Thu, 24 Jan 2019 16:45:55 +0000
Platform & Builds

for (int i = 0; i < GrabbedPrimitives.Num(); i++)
{
if (i >= GrabbedPrimitives.Num()) return;
if (!IsValid(GrabbedPrimitives[i])) continue;
UPrimitiveComponent* GrabbedPrimitive = GrabbedPrimitives[i];
}

Above is the bit of code causing the crash. It seems to break at ‘if (!IsValid(GrabbedPrimitives[i])) continue;’. I originally thought it was because of a null pointer issue so I added the IsValid check but that didn’t seem to fix things. I even added the check at the start of the loop to see if the array somehow changed size. Any ideas of what else could be causing the crash?

The array contains PrimitiveComponents for pawns, the pawns can be destroyed at any time before or after the loop, but not during it. The PrimitiveComponent is never destroyed by itself and the script calling this code is never destroyed. If it helps I’m using UE4 4.18.1.

2 posts - 1 participant