How can I fix this Segmentation fault using SFML?

与世无争的帅哥 提交于 2019-12-13 02:32:42

问题


I am having a segmentation fault error when running this code The error is triggered at the draw function of the custom object. I believe that its related to the address of the window.

GameObject *obj = new Dummy;

//game loop
while (window.isOpen())
{
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
            window.close();
    }
    window.clear();
    obj->draw(window);
    window.display();
}

return 0;

}

I pasted the whole code here


回答1:


I fixed it. The problem was that I was loosing the texture cause it wasn't created with new, so after the constructor created it then the sprite was banished.



来源:https://stackoverflow.com/questions/30008187/how-can-i-fix-this-segmentation-fault-using-sfml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!