<small id='YaWfp'></small><noframes id='YaWfp'>

    • <bdo id='YaWfp'></bdo><ul id='YaWfp'></ul>
  1. <legend id='YaWfp'><style id='YaWfp'><dir id='YaWfp'><q id='YaWfp'></q></dir></style></legend>

      <i id='YaWfp'><tr id='YaWfp'><dt id='YaWfp'><q id='YaWfp'><span id='YaWfp'><b id='YaWfp'><form id='YaWfp'><ins id='YaWfp'></ins><ul id='YaWfp'></ul><sub id='YaWfp'></sub></form><legend id='YaWfp'></legend><bdo id='YaWfp'><pre id='YaWfp'><center id='YaWfp'></center></pre></bdo></b><th id='YaWfp'></th></span></q></dt></tr></i><div id='YaWfp'><tfoot id='YaWfp'></tfoot><dl id='YaWfp'><fieldset id='YaWfp'></fieldset></dl></div>
      <tfoot id='YaWfp'></tfoot>
    1. SFML 在多线程中失败

      时间:2023-10-05

      <legend id='R8Hne'><style id='R8Hne'><dir id='R8Hne'><q id='R8Hne'></q></dir></style></legend>

      <small id='R8Hne'></small><noframes id='R8Hne'>

          <tfoot id='R8Hne'></tfoot>
            <tbody id='R8Hne'></tbody>

          • <i id='R8Hne'><tr id='R8Hne'><dt id='R8Hne'><q id='R8Hne'><span id='R8Hne'><b id='R8Hne'><form id='R8Hne'><ins id='R8Hne'></ins><ul id='R8Hne'></ul><sub id='R8Hne'></sub></form><legend id='R8Hne'></legend><bdo id='R8Hne'><pre id='R8Hne'><center id='R8Hne'></center></pre></bdo></b><th id='R8Hne'></th></span></q></dt></tr></i><div id='R8Hne'><tfoot id='R8Hne'></tfoot><dl id='R8Hne'><fieldset id='R8Hne'></fieldset></dl></div>

                <bdo id='R8Hne'></bdo><ul id='R8Hne'></ul>
                本文介绍了SFML 在多线程中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我是 sfml 和 c++ 的新手.我有一个使用 sfml 库来绘制图形的项目,但是当我向我的程序添加一个额外的线程时,它无法执行线程内的代码.这是我的代码:(请帮助我!)

                im new to sfml and c++.and I have a project that uses the sfml library's to draw the graphics but when I add an additional thread to my program it fails to execute the code inside the thread. this is my code:(please help me!)

                #include <SFMLGraphics.hpp>
                #include <SFMLwindow.hpp>
                #include <SFMLsystem.hpp>
                #include <iostream>
                #include <thread>
                #include <chrono>
                using namespace std;
                
                int h(sf::RenderWindow* win){
                    //do something
                    win->close();
                    this_thread::sleep_for(chrono::milliseconds(10));
                    return 0;
                }
                
                
                int main(){
                    sf::RenderWindow window(sf::VideoMode(800,600),"My window");
                    thread t1(h,&window);
                    _sleep(10000000);
                    t1.join();
                    return 0;
                }
                

                推荐答案

                http://www.sfml-dev.org/tutorials/2.0/graphics-draw.php#drawing-from-threads

                SFML 支持多线程绘图,你甚至不必做任何让它工作的东西.唯一要记住的是停用在另一个线程中使用它之前的一个窗口;那是因为一扇窗户(更准确地说是它的 OpenGL 上下文)不能在多个同时线程.

                SFML supports multi-threaded drawing, and you don't even have to do anything to make it work. The only thing to remember is to deactivate a window before using it in another thread; that's because a window (more precisely its OpenGL context) cannot be active in multiple threads at the same time.

                调用 window.setActive(false);在您的 main() 中,在您将其传递给线程之前.

                call window.setActive(false); in your main(), before you pass it off to the thread.

                请记住,您必须在 GUI 线程(主线程)中处理事件以获得最大的可移植性.

                And remember that you must handle events in the GUI thread (the main thread) for maximum portability.

                这篇关于SFML 在多线程中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:C++ 编译器如何合并相同的字符串文字 下一篇:调用函数时 C++ 访问冲突读取位置 0xcdcdcdcd 错误

                相关文章

                最新文章

              • <tfoot id='d6fDr'></tfoot>
                  • <bdo id='d6fDr'></bdo><ul id='d6fDr'></ul>

                  <i id='d6fDr'><tr id='d6fDr'><dt id='d6fDr'><q id='d6fDr'><span id='d6fDr'><b id='d6fDr'><form id='d6fDr'><ins id='d6fDr'></ins><ul id='d6fDr'></ul><sub id='d6fDr'></sub></form><legend id='d6fDr'></legend><bdo id='d6fDr'><pre id='d6fDr'><center id='d6fDr'></center></pre></bdo></b><th id='d6fDr'></th></span></q></dt></tr></i><div id='d6fDr'><tfoot id='d6fDr'></tfoot><dl id='d6fDr'><fieldset id='d6fDr'></fieldset></dl></div>

                  <small id='d6fDr'></small><noframes id='d6fDr'>

                  <legend id='d6fDr'><style id='d6fDr'><dir id='d6fDr'><q id='d6fDr'></q></dir></style></legend>