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

Author Topic: switching from 2.3.2 to 2.4.0 -> loading texture from sf::Thread now crashes  (Read 2757 times)

0 Members and 1 Guest are viewing this topic.

T5UN4M1

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Hello,

My program was running fine with sfml 2.3.2 but after updating it didn't work anymore.
after some debugging I came to the conclusion that trying to use sf::Texture in a sf::Thread doesn't work anymore.
I used sf::Thread to call a method that loads my texture while the current thread would keep running , allowing me to animate the loading screen without it freezing while the files were loading
void Media::load(void (*f)()){
// ...
    delete t;
    t = new sf::Thread(f);
    t->launch();
}
 
then the f() function loads some textures and creates sf::Sprite from them
but it doesn't work anymore.

as soon as I try to create a sf::Texture in the f() function it crashes.

I was previously using sfml 2.3.2 with TDM 4.7.1
I now use 2.4.0 with TDM 4.9.2

my program still works normally if I simply call f(); directly in the loading function, but that breaks my loading screens

information from debugging tool  when trying to use texture from thread (also see attachment):

Program received signal SIGSEGV, Segmentation fault.
In ntdll!RtlUlonglongByteSwap () (C:\Windows\system32\ntdll.dll)
217     D:\sfml-release\_Sources\SFML\src\SFML\Window\GlContext.cpp: No such file or directory.
#12 0x6e181f76 in sf::priv::GlContext::ensureContext () at D:\sfml-release\_Sources\SFML\src\SFML\Window\GlContext.cpp:217
Debugger finished with status 0
 

Is there a solution other than "stop using threads" ?

Thanks in advance!


« Last Edit: September 24, 2016, 06:53:22 pm by T5UN4M1 »

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
While I don't have an answer for the specific problem (I don't know enough about SFML's specific internals) I can offer the 'compromise' to which I came when animating loading screens. The trade off is to load my loading screen resources when the game first starts up, and keep them around for the duration of execution. Then the loading screen/thread launched between states merely animates and draws the resources, having no need to load anything, while the main thread continues to load the new state in the background. This does mean you can't have a loading screen on first start, and that some memory will always be allocated to these resources, but for something small like a rotating icon I find it fast enough to be an acceptable solution.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
The issue has already been reported multiple times on this forum (the search function is your friend) and there's already a fix in place: https://github.com/SFML/SFML/pull/1002

Please let us know whether using that branch fixes your problem.

CI Builds: http://www.sfml-dev.org/artifacts/by-branch/feature/no_internal_context/
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

T5UN4M1

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
it works fine now with it  :)

thank you very much!