【问题标题】:Segmentation Fault in SFML After calling sf::Window::closeSFML 中的分段错误调用 sf::Window::close 后
【发布时间】:2019-12-03 13:43:23
【问题描述】:

我正在尝试在与 main() 不同的线程上运行 SFML 窗口。调用 sf::Window::close 不会立即导致任何问题,但是在 main() 结束时,可能当 UI 对象被破坏时,会发生分段错误错误。如果不调用 sf::Window::close 则不会发生分段错误。

我正在运行完全更新的 Debian 10 安装。

#include <thread>
#include <SFML/Graphics.hpp>

int main() {
    sf::Window window(sf::VideoMode(500,500), "Test");

    std::thread th(&sf::Window::close, &window);
    th.join();
}

【问题讨论】:

    标签: c++ multithreading segmentation-fault sfml


    【解决方案1】:

    我发现了问题。您必须在关闭另一个线程之前停用窗口,就像这样。我最初在文档中错过了这一点。

    #include <thread>
    #include <SFML/Graphics.hpp>
    
    int main() {
        sf::Window window(sf::VideoMode(500,500), "Test");
    
        window.setActive(false);
    
        std::thread th(&sf::Window::close, &window);
        th.join();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多