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

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

        SFML 在多线程中失败

        SFML fails in multithreading(SFML 在多线程中失败)
        <tfoot id='ymQB8'></tfoot>
          <tbody id='ymQB8'></tbody>

            • <bdo id='ymQB8'></bdo><ul id='ymQB8'></ul>

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

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

                  <legend id='ymQB8'><style id='ymQB8'><dir id='ymQB8'><q id='ymQB8'></q></dir></style></legend>
                1. 本文介绍了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 在多线程中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to print vector#39;s data(如何打印矢量的数据)
                  Visual C++ appends 0xCC (int3) bytes at the end of functions(Visual C++ 在函数末尾附加 0xCC (int3) 字节)
                  How to use a variable inside a _T wrapper?(如何在 _T 包装器中使用变量?)
                  MSVC++ warning flags(MSVC++ 警告标志)
                  How to read file which contains uxxxx in vc++(如何在vc++中读取包含uxxxx的文件)
                  stack overflow error in C++ program(C++程序中的堆栈溢出错误)

                        <tbody id='8CFzp'></tbody>

                      <small id='8CFzp'></small><noframes id='8CFzp'>

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