簡體   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