I have a function that creates many entities at once, but it overflows the stack. What is the best way for me to do this?
Unhandled exception at 0x00007FFD5AA4DB45 (UnrealEditor-Sanes.dll) in UnrealEditor.exe: The stack cookie instrumentation code encountered a stack-related buffer overflow.
- My function:
void ASans::LabirintKostei(int vhodiVihodi[], int dlina, FVector skorostLabirinta)
{
for (int i = 0; i < dlina; i++)
{
if (vhodiVihodi[i] < 1)
vhodiVihodi[i] = 1;
if (vhodiVihodi[i] > 9)
vhodiVihodi[i] = 9;
}
float poyav = GetActorLocation().Y;
for (int i = 0; i < dlina; i++)
{
if (vhodiVihodi[i] > vhodiVihodi[i + 1])
for (int ii = vhodiVihodi[i]; ii > vhodiVihodi[i + 1]; ii--)
{
int stena[10]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
stena[ii] = 0;
stena[ii+1] = 0;
stena[ii-1] = 0;
StenaKostei(4, stena, skorostLabirinta, poyav);
poyav += 50;
UE_LOG(LogTemp, Warning, TEXT("mass %d yach %d"), i, ii);
}
if (vhodiVihodi[i] < vhodiVihodi[i + 1])
for (int ii = vhodiVihodi[i]; ii < vhodiVihodi[i + 1]; ii++)
{
int stena[10]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
stena[ii] = 0;
stena[ii + 1] = 0;
stena[ii - 1] = 0;
StenaKostei(4, stena, skorostLabirinta, poyav);
poyav += 50;
UE_LOG(LogTemp, Warning, TEXT("mass %d yach %d"), i, ii);
}
}
}
2 Function
void ASans::StenaKostei(int dlinaVolni, int raspologKost[], FVector skorostVolni, float y)
{
int schet = 0;
bool spawnit;
for (int i = 20; i <= 1370; i += 50)
{
if (schet%3 == 0)
spawnit = raspologKost[schet/3] != 0;
if (spawnit)
{
AKost* kost = SozdatKost(FVector(i, y, -100), dlinaVolni, skorostVolni, FRotator(0.0f, 0.0f, 0.0f));
kost->ZadatTochkyPoyavlenia(y-100);
if (y > 3450)
kost->IzmenitGraniciY(50,y+50);
}
schet++;
}
}