简体   繁体   中英

Run-Time Check Failure #2 - Stack around the variable 'application' was corrupted

Yes, this question has been asked hundreds of times. Still I couldn't find the answer I needed after sitting on this for hours. I'm not quite sure what I'm doing wrong. It's probably really stupid but I just couldn't figure it out. At the last line, that exception gets thrown. If you need anything else please ask . I'm using the SFML graphics Library. Here are all the files included in the Project: https://github.com/Lorekp/Run-Time-Check-Failure-2---Stack-around-the-variable-application-was-corrupted

#include "MainMenu.h"
#include "Application.h"
#include <SFML/Graphics.hpp>

int main()
{
    //making the window
    float wWidth = 1920.f;
    float wHeight = 1080.f;
    sf::Uint32 style = sf::Style::Titlebar | sf::Style::Close;
    sf::RenderWindow window(sf::VideoMode(wWidth,wHeight), style);
    MainMenu mainMenu;
    Application application;
    AssetManager assetManager;
    //putting the Main Menu on top
    window.clear();
    mainMenu.draw(window);
    window.display();
    while (window.isOpen())
    {
        sf::Event event;
        window.waitEvent(event);
        do {
            switch (event.type)
            {
            case sf::Event::EventType::Closed:
                window.close();
            case sf::Event::EventType::KeyReleased:
                if (event.key.code == sf::Keyboard::Up)
                {
                    mainMenu.MoveUp();
                    break;
                }
                else if (event.key.code == sf::Keyboard::Down) {
                    mainMenu.MoveDown();
                    break;
                }
                else if (event.key.code == sf::Keyboard::Return) {
                    sf::RenderWindow Play(sf::VideoMode(1920, 1080), "Labyrinth");
                    sf::RenderWindow Options(sf::VideoMode(1920, 1080), "Options");
                    sf::RenderWindow About(sf::VideoMode(1920, 1080), "About");

                    int x = mainMenu.MainMenuPressed();
                    switch (x)
                    {
                    case 0:
                        //Run Game
                        Options.close();
                        About.close();
                        application.run(Play, wWidth, wHeight, assetManager);
                        Play.close();
                        break;
                    case 1:
                        //Options
                    case 2:
                        //About
                    case 3:
                        //Quit Game
                        window.close();
                        break;
                    default:
                        break;
                    }
                    
                }
            case sf::Event::MouseButtonReleased:
                if (event.key.code == sf::Mouse::Left) {
                    sf::RenderWindow Play(sf::VideoMode(1920, 1080), "Labyrinth");
                    sf::RenderWindow Options(sf::VideoMode(1920, 1080), "Options");
                    sf::RenderWindow About(sf::VideoMode(1920, 1080), "About");
                    int x = mainMenu.MainMenuPressed();
                    switch (x)
                    {
                    case 0:
                        //Run Game
                        Options.close();
                        About.close();
                        application.run(Play, wWidth, wHeight, assetManager);
                        Play.close();
                        break;
                    case 1:
                        //Options
                    case 2:
                        //About
                    case 3:
                        //Quit Game
                        window.close();
                        break;
                    default:
                        break;
                    }
                }
            case sf::Event::EventType::MouseMoved:
                mainMenu.MouseMoved(window.mapPixelToCoords(sf::Mouse::getPosition(window)));
                break;
            default:
                break;
            }
        } while (window.pollEvent(event));
        window.clear();
        mainMenu.draw(window);
        window.display();
    }
    window.close();
    return 0;
}

Any suggestions are welcome. Please don't just comment about how dumb I am.

So...I kinda feel dumb now... In the included "MainMenu.h" file, I made a mistake, because of which a buffer overrun. I wasn't aware of the possibility, that a file, included in another file could cause this problem...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM