Create procedural mesh from animated skeletal mesh?

Seems that the code causes a crash with
Assertion failed: (Index >= 0) & (Index < ArrayNum) [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Array.h] [Line: 758] error. Did anybody experience this and knows what could be the cause?