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

Author Topic: [Solved] Loading Images Inside a Thread  (Read 46920 times)

0 Members and 1 Guest are viewing this topic.

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Loading Images Inside a Thread
« Reply #15 on: May 09, 2008, 04:39:51 pm »
If you really want to, create an invisible view and draw your images to it right after loading them to force them into OGL :)

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
[Solved] Loading Images Inside a Thread
« Reply #16 on: May 09, 2008, 04:49:44 pm »
That's one way to do it. :)
I don't think I would need such a function anyway. Was just trying to think ahead a little. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Loading Images Inside a Thread
« Reply #17 on: May 09, 2008, 05:02:34 pm »
Quote from: "workmad3"
If you really want to, create an invisible view and draw your images to it right after loading them to force them into OGL :)

Calling Bind() would be enough ;)
Laurent Gomila - SFML developer

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
[Solved] Loading Images Inside a Thread
« Reply #18 on: May 09, 2008, 05:58:08 pm »
Quote from: "Laurent"
Quote from: "workmad3"
If you really want to, create an invisible view and draw your images to it right after loading them to force them into OGL :)

Calling Bind() would be enough ;)

Give me a break... I haven't actually looked beyond class names in the 2d api so far :D I may look into it some more if I ever get beyond my action system in SFML ;)

lzr

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • http://lzr.cc
[Solved] Loading Images Inside a Thread
« Reply #19 on: May 10, 2008, 08:47:31 am »
Awesome, so I should expect everything to work upon the next release of SFML. And to think, I was about to change the loading code. Great work guys, my game is all finished. Hopefully the next version will come out soon so I can put it online. Is the new thread friendly image loading code in the SVN already?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Loading Images Inside a Thread
« Reply #20 on: May 10, 2008, 10:55:51 am »
It's not on SVN yet, I first have to complete another major modification. But it should be done in a few days.

I'm also thinking about releasing version 1.3 soon.
Laurent Gomila - SFML developer

lzr

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • http://lzr.cc
[Solved] Loading Images Inside a Thread
« Reply #21 on: June 22, 2008, 10:49:47 am »
I didn't see it in the Release log of SFML 1.3. Was this feature left out? I did program my own version that works, but it would great if it was in the official release.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Loading Images Inside a Thread
« Reply #22 on: June 22, 2008, 11:41:10 am »
It's only a little internal optimization which doesn't have any impact on the public interface, that's why it's not in the change log. But it's done, you can now load an image inside a thread ;)
Laurent Gomila - SFML developer

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
[Solved] Loading Images Inside a Thread
« Reply #23 on: July 15, 2008, 12:39:39 am »
This is a little old but..

I've read all of this but I'm still wondering if it's possible to load images in a thread and draw something indicating progress (like an sf::String with percent).
I think laurent said it isn't really possible.
But is it not possible even with a mutex?

Sorry, I'm new to multi-threading for the most part.
And could anyone provide a tiny bit of sample code for loading images in a thread?

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
[Solved] Loading Images Inside a Thread
« Reply #24 on: July 15, 2008, 01:18:16 am »
Okay, I answered my own question.
I'll post the code in a sec in case it helps someone else.

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
[Solved] Loading Images Inside a Thread
« Reply #25 on: July 15, 2008, 03:21:40 am »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] Loading Images Inside a Thread
« Reply #26 on: July 15, 2008, 04:53:56 am »
Nice, thanks :)
Laurent Gomila - SFML developer

dewyatt

  • Jr. Member
  • **
  • Posts: 75
    • View Profile
    • http://dewyatt.blogspot.com
[Solved] Loading Images Inside a Thread
« Reply #27 on: July 15, 2008, 08:04:22 am »
I'm happy to contribute.  :)

Updated the tutorial and code.
Also added a download.

dabo

  • Sr. Member
  • ****
  • Posts: 260
    • View Profile
    • http://www.dabostudios.net
[Solved] Loading Images Inside a Thread
« Reply #28 on: July 15, 2008, 11:46:23 am »
great addition, thanks.

opatut

  • Newbie
  • *
  • Posts: 25
    • View Profile
[Solved] Loading Images Inside a Thread
« Reply #29 on: November 07, 2010, 06:33:21 pm »
It's time to revive this thread...

I am currently trying to implement the same as mentioned above: a loading screen and a thread loading the images in background. My current problem is a segfault I get when loading an Image (sf::Image::LoadFromFile) from the thread into a boost::ptr_map.

GDB outputs the following:
Code: [Select]
#0  0x00007ffff4d08669 in glGetIntegerv () from /usr/lib/libGL.so.1
#1  0x00007ffff794cd83 in sf::Image::GetMaximumSize() ()
    from /usr/lib/libsfml-graphics.so.2.0
#2  0x00007ffff794ce38 in sf::Image::CreateTexture() ()
    from /usr/lib/libsfml-graphics.so.2.0
#3  0x00007ffff794d544 in sf::Image::LoadFromFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
    from /usr/lib/libsfml-graphics.so.2.0
#4 ...


This seems to be an OpenGL context error.
Did you change anything about loading images in different threads in SFML 2, Laurent? Or is it just my fault?

/edit: I try to do all this without a Mutex as it is not my intention to lock any thread. I just want them to run simultaneously. In the main thread I poll every tick whether the loading thread has finished, so I can continue my program. I do not need the synchronicity provided by a mutex and I want to avoid a deadlock.

 

anything