Hello, what is the safe way to use RenderTexture in asynchronous code? I need to render some objects to the texture in the background without suspending the main loop. Now I have the following code (simplified).
async_func(...)
{
std::vector<sf::Texture> textures;
RenderTexture t;
for(...)
{
//...
t.clear();
t.draw();
t.display();
textures.emplace_back(t.getTexture());
}
return textures;
}
main()
{
std::future<...>async_render;
//inside the loop
if(event) async_render=std::async(async_func, ...);
if (async_render.wait_for(0s) == std::future_status::ready)
{
auto c = async_render.get();
//....
}
//window.clear/draw/display();
}
And it works with varrying success because sometimes my app terminates abnormally with different errors:
X Error of failed request: GLXBadPbuffer
Major opcode of failed request: 152 (GLX)
Minor opcode of failed request: 28 (X_GLXDestroyPbuffer)
Serial number of failed request: 7663
Current serial number in output stream: 7666
or
(according to the callstack it raises from window.pollEvent(event))
GUI: ../../src/xcb_conn.c:215: write_vec: Assertion `!c->out.queue_len' failed.
I've also noticed that the first error occurs when textures.size()>1.
The callstack for the second error:
libc.so.6!__pthread_kill_implementation(int no_tid, int signo, pthread_t threadid) (pthread_kill.c:44)
libc.so.6!__pthread_kill_internal(int signo, pthread_t threadid) (pthread_kill.c:78)
libc.so.6!__GI___pthread_kill(pthread_t threadid, int signo) (pthread_kill.c:89)
libc.so.6!__GI_raise(int sig) (raise.c:26)
libc.so.6!__GI_abort() (abort.c:79)
libc.so.6!__assert_fail_base(const char * fmt, const char * assertion, const char * file, unsigned int line, const char * function) (assert.c:92)
libc.so.6!__GI___assert_fail(const char * assertion, const char * file, unsigned int line, const char * function) (assert.c:101)
libxcb.so.1![Unknown/Just-In-Time compiled code] (Unknown:0)
libxcb.so.1!xcb_writev (Unknown:0)
libX11.so.6!_XSend (Unknown:0)
libX11.so.6!_XFlush (Unknown:0)
libX11.so.6!XCheckIfEvent (Unknown:0)
libsfml-window-d.so.2.6!sf::priv::WindowImplX11::processEvents(sf::priv::WindowImplX11 * const this) (/LIBS/SFML-2.6.1/src/SFML/Window/Unix/WindowImplX11.cpp:723)
libsfml-window-d.so.2.6!sf::priv::WindowImpl::popEvent(sf::priv::WindowImpl * const this, sf::Event & event, bool block) (/LIBS/SFML-2.6.1/src/SFML/Window/WindowImpl.cpp:147)
libsfml-window-d.so.2.6!sf::WindowBase::pollEvent(sf::WindowBase * const this, sf::Event & event) (/LIBS/SFML-2.6.1/src/SFML/Window/WindowBase.cpp:165)
main() (GUI.cpp:123)