I am trying to spawn 65536 cubes using a UInstancedStaticMeshComponent, but the editor crashes the moment I try to spawn a simple 256x256 grid of cubes.
It works fine with 64x64, so I know the code works, and I assume there is a limit to the number of instances?
I get no warning, no errors. It just crashes.
for (size_t PixelY = 0; PixelY < TextureHeight; PixelY++)
{
for (size_t PixelX = 0; PixelX < TextureWidth; PixelX++)
{
if (PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight)
{
FTransform CurrentTrans = FTransform(FRotator(0, 0, 0), FVector(XOffset, YOffset, (PixelColor.R / 256.0f)*100.0f), FVector(1, 1, 1));
InstancedStaticComponent->AddInstance(CurrentTrans);
}
}
}
Above you can see the code that adds the instances.
It crashes at line 1223 of Vector.h, aka the second line in the code under here:
FORCEINLINE FVector::FVector(float InX, float InY, float InZ)
: X(InX), Y(InY), Z(InZ)
{
DiagnosticCheckNaN();
}
Making the floats smaller did not help. Is the engine unable to handle that many vectors and that is why it crashes?
The exception states: UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000002.
Thank you for your help.