C ++ SFML 0xCCCCCCCC访问违规错误

时间:2017-11-25 18:40:49

标签: c++ user-interface pointers sfml

我正在努力学习C ++。我正在尝试使用框架SFML (based on OpenGL)TGUI进行GUI编程。当我在Visual Studio(调试模式)中运行我的基本程序(只是窗口初始化和创建按钮)时,它会抛出异常:访问冲突读取位置0xCCCCCCCC。我发现,0xCCCCCCCC是一个特定的内存模式,意味着我在堆栈上做了未初始化的内存。但是我在我的计划中在哪里这样做?我的代码:

#include <TGUI/Gui.hpp>
#include <TGUI\TGUI.hpp>
#include <TGUI\Widgets\Button.hpp>

using namespace std;

int main() {
    tgui::Button::Ptr button = tgui::Button::create("Test");   //HERE THE EXCEPTION IS THROWN
    sf::RenderWindow window(sf::VideoMode(800, 600), "Fenster");
    tgui::Gui gui(window);
    gui.add(button, "Hallo");

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            // When the window is closed, the application ends
            if (event.type == sf::Event::Closed)
            {
                window.close();
            } else if (event.type == sf::Event::Resized){
                window.setView(sf::View(sf::FloatRect(0, 0, event.size.width, event.size.height)));
                gui.setView(window.getView());
            }

            // Pass the event to all the widgets
            gui.handleEvent(event);
        }

        window.clear();

        // Draw all created widgets
        gui.draw();

        window.display();
    }

delete button;
button = NULL; 
return EXIT_SUCCESS;
}

任何帮助都会很好。谢谢!

0 个答案:

没有答案