Spoke with eXpl0it3r on irc a bit about this.
Anyway, so I have a multithreaded application. Seems that calling
sf::Texture::update repeatedly, leaks. Tracking it revealed that it's specifically
sf::priv::WglContext::createContext which leaks, and it leaks a lot, very quickly (~42 MiB in 3 sec).
sf::priv::WglContext::makeCurrent also causes a leak, but no where near as much (~72 KiB in 3 sec).
Essentially, my application has a thread controlled by an SDK I'm using, of which I have no control over. It calls a function that I write, and waits until it returns. I have this function launch a thread to do some processing on what the SDK passed to me, and detach from it, so I can let the SDK's thread continue.
I'm taking the image it gives, me converting it to an
sf::Texture, and then in another thread, drawing said
sf::Texture with an
sf::Sprite on a
sf::RenderWindow.
I have mutexes around any access to the texture.
Minimal example:
#include <SFML/Graphics.hpp>
#include <mutex>
#include <thread>
int main()
{
using byte = unsigned char;
sf::Texture texture;
std::mutex textureMutex;
std::thread([&]()
{
while (true)
{
sf::sleep(sf::milliseconds(32));
std::thread([&]()
{
std::lock_guard<std::mutex> textureLock(textureMutex);
std::vector<byte> bytes(640 * 480 * 4);
if (texture.getSize() == sf::Vector2u{0, 0})
{
texture.create(640, 480);
}
texture.update(bytes.data());
}).detach();
}
}).join();
return 0;
}
The
sf::sleep is there to simulate time waiting for the call from the SDK.
Also, without it, SFML outputs this:
An internal OpenGL call failed in TextureSaver.cpp (38) : GL_INVALID_OPERATION,
the specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (390) : GL_INVALID_OPERATION, the
specified operation is not allowed in the current state
An internal OpenGL call failed in Texture.cpp (391) : GL_INVALID_OPERATION, the
specified operation is not allowed in the current state
An internal OpenGL call failed in TextureSaver.cpp (45) : GL_INVALID_OPERATION,
the specified operation is not allowed in the current state
Failed to create an OpenGL context for this window:
and an abort() gets called from crtmbox.c for every set of the above messages. Though, that seems less relevant.
Also,
here is the VS *.diagsession file from running VS' Memory Analysis tool (had to put it on my Dropbox, as it's too big).
Oops, forgot versions and hardware and stuff:
OS: Windows 8.1 Enterprise
CPU: i7-4790
GPU: Intel HD Graphics 4600 (tried default driver and latest driver)
SFML: 2.3 from Github, compiled myself
Given that it's an Intel GPU, I'm assuming this is probably a driver issue... I'd try another graphics card, but I don't think we have any here at work.