如何使用 SFML 修复此分段错误? [英] How can I fix this Segmentation fault using SFML?

查看:42
本文介绍了如何使用 SFML 修复此分段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行此代码时遇到分段错误错误该错误是在自定义对象的绘制函数处触发的.我相信它与窗口的地址有关.

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;

}

我粘贴了整个代码这里

推荐答案

我修复了它.问题是我丢失了纹理,因为它不是用 new 创建的,所以在构造函数创建它之后,精灵就被放逐了.

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.

这篇关于如何使用 SFML 修复此分段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆