Alright just in case anyone else get this problem I will post a hotfix here. It's not a real solution but it will make it work in Release. Don't know if it will help you find the problem Laurent. But for everyone else this will fix your problem if you are having problems with textures/images being loaded in one thread and then used in another.
HOW TO FIX IT!
I created an image that is always loaded last that I call "bugfix.jpg". So just make sure that you always load one last image. You don't need to draw it or anything. You only need to load it last.
WHAT IS HAPPENING?
Well I tried to understand it but it puzzled me... Because if I changed the order of how I drawed the sprite and cube, it was still the same texture that was being omitted.
So I thought... "Hmm let's see if we can get the previous behaviour back"
The behaviour I was thinking about was that the sprite texture was omitted. So I commented out the render call of my cube so that it's texture was never bound. But I was surprised. The sprite was still being drawn with it's texture, not giving me the same result as before! I was puzzled but started thinking... What's the difference between before and now? And it occurred to me, I'm loading a second texture! So I tried just loading a third texture into memory, not drawing it or anything. And it worked!
So somehow it seems like the last image you load into memory is in fact... not loaded into memory until next image is being loaded. This of course only seem to apply if you are loading a texture/image in a thread that is not main and then use this texture/image for drawing in another thread than it was loaded in(also not main).
Example code for reproducing the problem also the hotfix is presented in commented code.
#include <SFML\Graphics.hpp>
sf::Image* ourTexture = NULL;
bool ourTextureLoaded = false;
bool ourIsRunning = true;
void LogicFunction()
{
ourTexture->Create(500, 500, sf::Color(0, 255, 0));
ourTextureLoaded = true;
/* These two lines of code fixes everything!
* sf::Image bugFixImage;
* bugFixImage.Create(1,1);
*/
}
void RenderFunction( sf::RenderWindow *aWindow )
{
aWindow->SetActive( true );
sf::Sprite sprite;
bool spriteTextureSet = false;
while( ourIsRunning == true )
{
aWindow->Clear();
if( ourTextureLoaded == true )
{
if( spriteTextureSet == false )
{
sprite.SetImage( *ourTexture );
spriteTextureSet = true;
}
aWindow->Draw( sprite );
}
aWindow->Display();
sf::Sleep( 0 );
}
}
int main()
{
ourTexture = new sf::Image;
sf::RenderWindow window( sf::VideoMode( 800, 600 ), "Test" );
window.SetActive( false );
sf::Thread logics( LogicFunction );
sf::Thread graphics( RenderFunction, &window );
logics.Launch();
graphics.Launch();
while( ourIsRunning == true )
{
sf::Event event;
while( window.PollEvent( event ) == true )
{
if( event.Type == sf::Event::Closed )
{
ourIsRunning = false;
window.Close();
}
}
sf::Sleep( 0 ) ;
}
return 0;
}