Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Solved] Drawing to a sf::RenderTexture on separate thread  (Read 1988 times)

0 Members and 1 Guest are viewing this topic.

hartwall

  • Newbie
  • *
  • Posts: 2
    • View Profile
[Solved] Drawing to a sf::RenderTexture on separate thread
« on: January 18, 2016, 10:54:31 pm »
Hey folks! I'm trying to create a game using sfml and Qt on Windows! I want to separate all the game logic and rendering to a separate QThread and draw the result on a canvas on the main gui-thread. I was hoping I could render the picture in a sf::RenderTexture and signal the texture using Qt:s signal/slot system to the gui-thread. However, the program always crashes with a segmentation fault when calling the sf::RenderTexture::getTexture() in the game-thread. Any ideas? Here's some debug-info:
0       ntdll!RtlReleaseSRWLockShared                   0x77e64d78     
1       ntdll!RtlAllocateHeap                   0x77e62eab     
2       ntdll!RtlAllocateHeap                   0x77e62c0e     
3       ntdll!RtlpNtSetValueKey                 0x77f0d199     
4       ntdll!RtlReleaseSRWLockShared                   0x77e64b10     
5       ntdll!RtlAllocateHeap                   0x77e62eab     
6       ntdll!RtlAllocateHeap                   0x77e62c0e     
7       msvcrt!malloc                   0x77ba7990     
8       libstdc++-6!_Znwj                       0xab372da      
9       (anonymous namespace)::getInternalContext       GlContext.cpp   155     0xa81b35       
10      sf::priv::GlContext::ensureContext      GlContext.cpp   213     0xa81dd6                               
 
« Last Edit: January 20, 2016, 05:40:47 pm by hartwall »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Drawing to a sf::RenderTexture on separate thread
« Reply #1 on: January 19, 2016, 09:41:07 am »
do not try to make multithreaded app in SFML. opengl does not support multithreading in current version. You will not increase perfomence. If you want multithreding then wait for new vulcan API. ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10837
    • View Profile
    • development blog
    • Email
Re: Drawing to a sf::RenderTexture on separate thread
« Reply #2 on: January 19, 2016, 10:57:20 am »
I want to separate all the game logic and rendering to a separate QThread
Don't.

Multi-threading is an advanced topic, that requires very good knowledge of the memory model and programming in general. There are many, many problems that can arise from multi-threading and there's nearly no gain in doing so, especially since as Mr_Blame said, OpenGL is not multi-threaded and additionally to draw something you need a complete state, so you can't really parallelize it.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hartwall

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Drawing to a sf::RenderTexture on separate thread
« Reply #3 on: January 20, 2016, 05:40:32 pm »
I understand that it is difficult but I really want to use Qt for the menus since they are an important part of the game.

My solution is to start a new QThread with it's own sf::Window to show the game world and minimize the menu(-thread) while the game itself is active.