Hi! I am programming multithread rendering with opengl. I create 2 new threads and a new context for each.
Memory rises on SDL_GL_MakeCurrent(window, xContext)
call.
SDL_GLContext mainContext = nullptr;
SDL_GLContext simulationThreadContext = nullptr;
SDL_GLContext renderThreadContext = nullptr;
SDL_Window* window = nullptr;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6);
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
window = SDL_CreateWindow("window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1600, 900, SDL_WINDOW_OPENGL);
simulationThreadContext = SDL_GL_CreateContext(window);
renderThreadContext = SDL_GL_CreateContext(window);
mainContext = SDL_GL_CreateContext(window);
//glew things
InitOpengl();
std::thread simulationThread;
std::thread renderThread;
while (!quit)
{
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
taskQueue.clear();
simulationThread = std::thread([&]() {
SDL_GL_MakeCurrent(window, simulationThreadContext);
//UpdateSim();
//simDone.store(true);
SDL_GL_MakeCurrent(window, nullptr);
});
renderThread = std::thread([&]() {
SDL_GL_MakeCurrent(window, renderThreadContext);
//while (!(taskQueue.empty() && simDone.load())) {
// RenderSim();
//}
SDL_GL_MakeCurrent(window, nullptr);
});
simulationThread.join();
renderThread.join();
SDL_GL_MakeCurrent(window, mainContext);
SDL_GL_SwapWindow(window);
SDL_GL_MakeCurrent(window, nullptr);
}
SDL_GL_DeleteContext(simulationThreadContext);
SDL_GL_DeleteContext(renderThreadContext);
SDL_GL_DeleteContext(mainContext);
SDL_DestroyWindow(window);
I commented out task queue part that is responsible for adding work and doing it, to be sure that it is not problem with this and memleak still occurs.
Problem with memory fixes when SDL_GL_MakeCurrent()
is commented.
Is there a problem on my side?