Note: I placed this question in the graphics sub-forum, but I am not sure the problem actually comes from a graphic element.
My program copies instances of sf::sprite quite heavily between two threads (one thread sets the sprites, copy these into a std::multimap, and then swaps its std::multimap whith the rendering thread's, and the other thread renders all the items of the std::multimap).
The program starts running fine for a few frames on ubuntu (gcc), and on windows (vc++ 2008),
but after a few seconds, the program hangs (gcc) or raises an assert (vc++).
Here is the gdb stack trace when I hit ^C, a few seconds after the program hangs.
(gdb) bt
#0 0x00007ffff7297acd in std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x000000000040a90e in std::_Rb_tree<sf::ResourcePtr<sf::Image>*, sf::ResourcePtr<sf::Image>*, std::_Identity<sf::ResourcePtr<sf::Image>*>, std::less<sf::ResourcePtr<sf::Image>*>, std::allocator<sf::ResourcePtr<sf::Image>*> >::_M_insert_ (this=0xdc82d0, __x=0x0, __p=0xde5130, __v=@0x7fffffffd338: 0x7fffffffd568)
at /usr/include/c++/4.6/bits/stl_tree.h:973
#2 0x000000000040a447 in std::_Rb_tree<sf::ResourcePtr<sf::Image>*, sf::ResourcePtr<sf::Image>*, std::_Identity<sf::ResourcePtr<sf::Image>*>, std::less<sf::ResourcePtr<sf::Image>*>, std::allocator<sf::ResourcePtr<sf::Image>*> >::_M_insert_unique (this=0xdc82d0, __v=@0x7fffffffd338: 0x7fffffffd568)
at /usr/include/c++/4.6/bits/stl_tree.h:1291
#3 0x000000000040a191 in std::set<sf::ResourcePtr<sf::Image>*, std::less<sf::ResourcePtr<sf::Image>*>, std::allocator<sf::ResourcePtr<sf::Image>*> >::insert (this=0xdc82d0, __x=@0x7fffffffd338: 0x7fffffffd568)
at /usr/include/c++/4.6/bits/stl_set.h:410
#4 0x000000000040a129 in sf::Resource<sf::Image>::Connect (this=0xdc82d0, Observer=...)
at /usr/include/SFML/System/Resource.inl:77
#5 0x000000000040a066 in sf::ResourcePtr<sf::Image>::ResourcePtr (this=0x7fffffffd568, Copy=...)
at /usr/include/SFML/System/ResourcePtr.inl:57
#6 0x0000000000409d62 in sf::Sprite::Sprite (this=0x7fffffffd4b8) at /usr/include/SFML/Graphics/Sprite.hpp:45
Then follows my code stack trace, where I set the sprite image.
Here is the message in visual studio.
Debug assertion failed!
Program: ...
File: c:\program files (x86)\microsoft visual studio 9.0/vc/include/xtree
Line: 304
Expression: map/set iterators incompatible
For information ...
(Press Retry to debug the application)
And the visual studio stack trace.
msvcp90d.dll!std::_Debug_message(const wchar_t * message=0x01432988, const wchar_t * file=0x014325d8, unsigned int line=304) Line 24 C++
> ***.exe!std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator::operator==(const std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator & _Right=0xfeeefeee {myResource=??? }) Line 304 + 0x17 bytes C++
***.exe!std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator::operator!=(const std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator & _Right=0xfeeefeee {myResource=??? }) Line 316 + 0xc bytes C++
***.exe!std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::erase(std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator _First=0xfeeefeee {myResource=??? }, std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::const_iterator _Last=0xfeeefeee {myResource=??? }) Line 942 + 0xc bytes C++
***.exe!std::_Tree<std::_Tset_traits<sf::ResourcePtr<sf::Image> *,std::less<sf::ResourcePtr<sf::Image> *>,std::allocator<sf::ResourcePtr<sf::Image> *>,0> >::erase(sf::ResourcePtr<sf::Image> * const & _Keyval=0x0036f64c) Line 953 + 0x57 bytes C++
***.exe!sf::Resource<sf::Image>::Disconnect(sf::ResourcePtr<sf::Image> & Observer={...}) Line 88 C++
***.exe!sf::ResourcePtr<sf::Image>::operator=() + 0x39 bytes
***.exe!sf::Sprite::SetImage() + 0x89 bytes
Then my stack trace.
I could not find much on how the sf::Resource works, and why it is used here.
Attempts to see something with valgrind+memcheck were unsuccessful, due to lots of errors comming from the ati drivers library.
Any ideas on what could cause this problem ?