I have coded an if statement spanning a few thousand lines that contains many other nested if statements within. I get a stack overflow error when I don't comment out a lot of it. I know it's due to size because I found that this particular if statement can only handle 6 different blocks of code [the block that says "if (mainmenu1.equipment1A) ] [there are 10 of these per if ((mainmenu1.player1equipment && (Player1.job == 1)) ||... block] and it doesn't matter which blocks are un-commented out if there are 7 no matter which 7 it will give me this following error. It is strange though, This code is part of the code in a game I am working on and the code is in an entirely different gamestate case in a switch statement, and upon startup this code should not be read. I do not receive a compile error when building with none of the code commented out, but upon startup i get this error. Shouln't it be a run time error instead? But in that case, I should not get the error until the program reads the code. I will include a sample of the code, it is about 70,000 lines in all but it is repetitive so imagine this following code times 70.
First-chance exception at 0x103B38B7 (ig7icd32.dll) in SFML.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x01072000). Unhandled exception at 0x103B38B7 (ig7icd32.dll) in SFML.exe: 0xC00000FD: Stack overflow (parameters: 0x00000000, 0x01072000).
First-chance exception at 0x101AC0BE (ig7icd32.dll) in SFML.exe: 0xC0000005: Access violation writing location 0x0107091C. Unhandled exception at 0x101AC0BE (ig7icd32.dll) in SFML.exe: 0xC0000005: Access violation writing location 0x0107091C.
//equipment text
if (mainmenu1.equipmentmenu2)
{
if (executeequipmenttextonce)
{
executeequipmenttextonce = false;
if (mainmenu1.rightselected)
{
if ((mainmenu1.player1equipment && (Player1.job == 1)) || (mainmenu1.player2equipment && (Player2.job == 1)) || (mainmenu1.player3equipment && (Player3.job == 1)))
{
if (mainmenu1.equipment1A)
{
if (!mainmenu1.knightweapon1displayed && mainmenu1.knightweapon1)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon1displayed = true;
textDisplay16.text.setString("Broadsword");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw1));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon2displayed && mainmenu1.knightweapon2)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon2displayed = true;
textDisplay16.text.setString("Ea");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw2));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon3displayed && mainmenu1.knightweapon3)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon3displayed = true;
textDisplay16.text.setString("Zangetsu");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw3));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon4displayed && mainmenu1.knightweapon4)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon4displayed = true;
textDisplay16.text.setString("Silver Fleurette");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw4));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon5displayed && mainmenu1.knightweapon5)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon5displayed = true;
textDisplay16.text.setString("Lawliet");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw5));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon6displayed && mainmenu1.knightweapon6)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon6displayed = true;
textDisplay16.text.setString("Luminous Edge");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw6));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon7displayed && mainmenu1.knightweapon7)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon7displayed = true;
textDisplay16.text.setString("Heaven's Saber");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw7));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon8displayed && mainmenu1.knightweapon8)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon8displayed = true;
textDisplay16.text.setString("Crystal Edge");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw8));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon9displayed && mainmenu1.knightweapon9)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon9displayed = true;
textDisplay16.text.setString("Triple Zoro");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw9));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon10displayed && mainmenu1.knightweapon10)
{
mainmenu1.equipment1A = false;
mainmenu1.knightweapon10displayed = true;
textDisplay16.text.setString("Elsword");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw10));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY1);
textDisplayArray16.push_back(textDisplay16);
}
}
else if (mainmenu1.equipment2A)
{
if (!mainmenu1.knightweapon1displayed && mainmenu1.knightweapon1)
{
mainmenu1.equipment2A = false;
mainmenu1.knightweapon1displayed = true;
textDisplay16.text.setString("Broadsword");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY2);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw1));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY2);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon2displayed && mainmenu1.knightweapon2)
{
mainmenu1.equipment2A = false;
mainmenu1.knightweapon2displayed = true;
textDisplay16.text.setString("Ea");
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY2);
textDisplayArray16.push_back(textDisplay16);
textDisplay16.text.setString(to_string(mainmenu1.knightw2));
textDisplay16.text.setPosition(view1.getCenter().x - window.getSize().x / 2 + equipmentPositionX1 + equipmentstockpositionx, view1.getCenter().y - window.getSize().y / 2 + equipmentPositionY2);
textDisplayArray16.push_back(textDisplay16);
}
else if (!mainmenu1.knightweapon3displayed && mainmenu1.knightweapon3)
{
mainmenu1.equipment2A = false;
mainmenu1.knightweapon3displayed = true;
textDisplay16.text.setString("Zangetsu");
Technically, an if statement does not consume stack space.
Function calls within an if expression may cause a StackOverflow.
Allocating too many local variables in the statement block may cause a stack overflow.
Allocating large variables in the statement block may cause a stack overflow.
Recursive functions that are not limited may cause a stack overflow.
Recursive functions that use a lot of local variables or parameters may cause a stack overflow.
An if statement is generally evaluated as a compare instruction and a branch statement. These instructions don't occupy stack space.
Your errors are probably located elsewhere.
Use a debugger to find the root cause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With