100% reproducible crash when adding many instances to instanced static mesh over multiple frames

CONFIGURATION
I am testing on Mac OS X 10.12.6 (16G29) with Unreal Version: 4.18.2-3794801+++UE4+Release-4.18 (although I also saw this bug with 4.18.0). The editor seems to run with Metal when it runs. I have not tested on Windows.

SUMMARY
A very simple C++ program that adds instances to an instanced static mesh crashes 100% of the time if (1) the number of instances goes above about 500 and (2) the instances are added 25 at a time over multiple frames (there is no crash if all 500 or even 2500 instances are added in a single frame). The crash occurs inside Unreal’s Metal support.

REPRO STEPS
Here is an attached project

LINK

The code is in LifeComponent.cpp and is very simple. There is one map FirstMap, and the important object is the LifeActor1. LifeActor1 has a LifeComponent, and a blueprint which creates an instanced static mesh and assigns it as a variable to LifeComponent, then sets up a timer to call the function Iterate on LifeComponent.

Select LifeActor1 and in details select Life. The important properties are “Gens”, “Width”, “Height” and “All At Once”. The c++ code will create a tower of cube instances. Each floor of the tower is WidthXHeight cubes, and it grows up to Gens cubes tall. If you click All At Once it will build the entire tower in the BeginPlay event, otherwise it will build it one floor every 100 ms. To test, I recommend using the “Standalone” play mode (you will crash a lot), and changing the “Gens” and “All at Once” variables.

In my testing:

  • Testing with Gens=10, AllAtOnce=FALSE: No crash ever
  • Testing with Gens=100, AllAtOnce=TRUE: No crash ever
  • Testing with Gens=20, AllAtOnce=FALSE: Crash a majority of the time but less than 100%
  • Testing with Gens=100, AllAtOnce=FALSE: Crash every time

When the crash occurs, it prints an assert

[2017.12.21-06.55.48:813][976]PIE: Play in editor start time for /Game/UEDPIE_0_FirstMap -0.152
[2017.12.21-06.55.49:771][987]LogMac: Error: appError called: Assertion failed: Size >= CreateInfo.ResourceArray->GetResourceDataSize() [File:/Users/build/Build/++UE4+Release-4.18+Compile/Sync/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalVertexBuffer.cpp] [Line: 299] 

and the crash always has the same stack

 SEGV_MAPERR at 0x3

FGenericPlatformMisc::RaiseException(unsigned int) Address = 0x10571499b (filename not found) [in UE4Editor-Core.dylib]
FMacErrorOutputDevice::Serialize(wchar_t const*, ELogVerbosity::Type, FName const&) Address = 0x10b5d1c19 (filename not found) [in UE4Editor-ApplicationCore.dylib]
FOutputDevice::Logf(wchar_t const*, ...) Address = 0x1059c2c9d (filename not found) [in UE4Editor-Core.dylib]
FDebug::AssertFailed(char const*, char const*, int, wchar_t const*, ...) Address = 0x105938efb (filename not found) [in UE4Editor-Core.dylib]
FMetalDynamicRHI::RHICreateVertexBuffer(unsigned int, unsigned int, FRHIResourceCreateInfo&) Address = 0x1289131da (filename not found) [in UE4Editor-MetalRHI.dylib]
FMetalDynamicRHI::CreateVertexBuffer_RenderThread(FRHICommandListImmediate&, unsigned int, unsigned int, FRHIResourceCreateInfo&) Address = 0x128913561 (filename not found) [in UE4Editor-MetalRHI.dylib]
FStaticMeshInstanceBuffer::InitRHI() Address = 0x10794b14a (filename not found) [in UE4Editor-Engine.dylib]
FRenderResource::UpdateRHI() Address = 0x106c6e684 (filename not found) [in UE4Editor-RenderCore.dylib]
FStaticMeshInstanceBuffer::UpdateRHIVertexBuffer(int, unsigned int, unsigned int) Address = 0x10794b824 (filename not found) [in UE4Editor-Engine.dylib]
FStaticMeshInstanceBuffer::UpdateRHIVertexBuffer(TSet<int, DefaultKeyFuncs<int, false>, FDefaultSetAllocator> const&) Address = 0x10794b693 (filename not found) [in UE4Editor-Engine.dylib]
TGraphTask<FInstancedStaticMeshRenderData::UpdatePerInstanceRenderData(TSet<int, DefaultKeyFuncs<int, false>, FDefaultSetAllocator> const&)::EURCMacro_FPerInstanceRenderDataBufferUpdate>::ExecuteTask(TArray<FBaseGraphTask*, FDefaultAllocator>&, ENamedThreads::Type) Address = 0x107978b3c (filename not found) [in UE4Editor-Engine.dylib]
FNamedTaskThread::ProcessTasksNamedThread(int, bool) Address = 0x105730f1c (filename not found) [in UE4Editor-Core.dylib]
FNamedTaskThread::ProcessTasksUntilQuit(int) Address = 0x10572ffc8 (filename not found) [in UE4Editor-Core.dylib]
FTaskGraphImplementation::ProcessThreadUntilRequestReturn(ENamedThreads::Type) Address = 0x10572c0ae (filename not found) [in UE4Editor-Core.dylib]
RenderingThreadMain(FEvent*) Address = 0x106c672a1 (filename not found) [in UE4Editor-RenderCore.dylib]
FRenderingThread::Run() Address = 0x106c7bd17 (filename not found) [in UE4Editor-RenderCore.dylib]
FRunnableThreadPThread::Run() Address = 0x1057a527e (filename not found) [in UE4Editor-Core.dylib]
FRunnableThreadPThread::_ThreadProc(void*) Address = 0x10574ffc7 (filename not found) [in UE4Editor-Core.dylib]
_pthread_body Address = 0x7fffdac9093b (filename not found) [in libsystem_pthread.dylib]
_pthread_body Address = 0x7fffdac90887 (filename not found) [in libsystem_pthread.dylib]
thread_start Address = 0x7fffdac9008d (filename not found) [in libsystem_pthread.dylib]

The assert and crash stack are similar to the assert in Unreal Engine Issues and Bug Tracker (UE-48710), which is currently labeled as having no known repro steps. But maybe this is a coincidence.

EXPECTED BEHAVIOR
Adding instances to an instanced static array should not crash. If there is a limit on adding instances to an instanced static array, it should print some sort of useful error or assert at AddInstance time and not crash later.

Hi , I have tested this with your sample project on Mac OS 10.13.2 and did not have any issues. I would ask that if you have the ability to upgrade to 10.13.2 please do and let me know if you still encounter the crash. Also if you could let me know which version of Xcode you are using as well as the system specs of your Mac that would be appreciated. Thank you.

Please let me know when you have gotten the chance to upgrade your OS and test this. Thank you.

Hello. I apologize for the delay. I have tested with High Sierra and the problem is NOT resolved. Here are my current results.

I upgraded to High Sierra 10.13.2 (17C88) and XCode 9.2 (9C40b).

Test: All At Once = False, Gens = 1
Result: No crash

Test: All At Once = False, Gens = 2
Result: No crash

Test: All At Once = False, Gens = 10
Result: Crash, assert printed

[2018.01.05-14.52.40:377][ 10]LogMac: Error: appError called: Assertion failed: Size >= CreateInfo.ResourceArray->GetResourceDataSize() [File:/Users/build/Build/++UE4+Release-4.18+Compile/Sync/Engine/Source/Runtime/Apple/MetalRHI/Private/MetalVertexBuffer.cpp] [Line: 299] 

Crash stack implicates FMetalDynamicRHI::RHICreateVertexBuffer

Attached:
Crash report zip link text
Final log (might not be in zip?) link text
System configuration as printed by System Information link text

In addition, since upgrading I find that the zip I uploaded above no longer compiles for me. My local backup DOES compile. Let me know if you need me to create a new zip file.

Hello, I would like to stress this is not resolved and I can still reproduce it. Can it be reopened?

Hi, After testing this again I still have not encountered a crash. Is there any other setting or piece of information that may have been left out.

Also is this crash only happening in your current project, have you tried making a clean project and seeing if that crashes as well.

As is stands currently I was not able to reproduce the crash in both your provided project and a new project.