简体   繁体   English

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

[英]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.我正在使用 SFML 图形库。 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以下是项目中包含的所有文件: 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.所以......我现在有点傻......在包含的“MainMenu.h”文件中,我犯了一个错误,因为缓冲区溢出。 I wasn't aware of the possibility, that a file, included in another file could cause this problem...我不知道包含在另一个文件中的文件可能会导致此问题的可能性...

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

相关问题 运行时检查失败 #2 - 变量“IDNumber”周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'IDNumber' was corrupted 运行时检查失败#2-变量&#39;indices&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'indices' was corrupted 运行时检查失败#2-变量&#39;result&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'result' was corrupted 运行时检查失败#2-变量&#39;numberchoices&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'numberchoices' was corrupted 运行时检查失败#2-变量&#39;ex&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'ex' was corrupted 运行时检查失败#2-变量&#39;NearID&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'NearID' was corrupted 运行时检查失败-变量周围的堆栈已损坏 - Run-Time Check Failure - Stack around variable was corrupted 运行时检查失败#2-变量&#39;s&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 's' was corrupted 运行时检查失败#2 - 变量&#39;B&#39;周围的堆栈已损坏 - Run-Time Check Failure #2 - Stack around the variable 'B' was corrupted 运行时检查失败#2-变量周围的堆栈-已损坏 - Run-Time Check Failure #2 - Stack around the variable — was corrupted
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM