繁体   English   中英

运行时检查失败 #2 - 变量“应用程序”周围的堆栈已损坏

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

是的,这个问题已经被问了数百次了。 坐了几个小时后,我仍然找不到我需要的答案。 我不太确定我做错了什么。 这可能真的很愚蠢,但我就是想不通。 在最后一行,该异常被抛出。 如果您还需要什么,请询问 我正在使用 SFML 图形库。 以下是项目中包含的所有文件: 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;
}

欢迎任何建议。 请不要只评论我有多愚蠢。

所以......我现在有点傻......在包含的“MainMenu.h”文件中,我犯了一个错误,因为缓冲区溢出。 我不知道包含在另一个文件中的文件可能会导致此问题的可能性...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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