Hi guys, im having a little problem fixing a bug in my program since i multi-threaded it. The app is a little video converter i wrote for fun. To help you understand the problem, ill first explain how the program is made. Im using Delphi to do the GUI/Windows part of the code, then im loading a c++ dll for the video conversion. The problem is not related to the video conversion, but with OpenGL only. The code work like this:
DWORD WINAPI JobThread(void *params)
{
for each files {
...
_ConvertVideo(input_name, output_name);
}
}
void EXP_FUNC _ConvertVideo(char *input_fname, char *output_fname)
{
// Note that im re-initializing and cleaning up OpenGL each time this function is called...
CGLEngine GLEngine;
...
// Initialize OpenGL
GLEngine.Initialize(render_wnd);
GLEngine.CreateTexture(dst_width, dst_height, 4);
// decode the video and render the frames...
for each frames {
...
GLEngine.UpdateTexture(pY, pU, pV);
GLEngine.Render();
}
cleanup:
GLEngine.DeleteTexture();
GLEngine.Shutdown();
// video cleanup code...
}
With a single thread, everything work fine. The problem arise when im starting the thread for a second time, nothing get rendered, but the encoding work fine. For example, if i start the thread with 3 files to process, all of them render fine, but if i start the thread again (with the same batch of files or not...), OpenGL fail to render anything.
Im pretty sure it has something to do with the rendering context (or maybe the window DC?). Here a snippet of my OpenGL class:
bool CGLEngine::Initialize(HWND hWnd)
{
hDC = GetDC(hWnd);
if(!SetupPixelFormatDescriptor(hDC)){
ReleaseDC(hWnd, hDC);
return false;
}
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
// more code ...
return true;
}
void CGLEngine::Shutdown()
{
// some code...
if(hRC){wglDeleteContext(hRC);}
if(hDC){ReleaseDC(hWnd, hDC);}
hDC = hRC = NULL;
}
The full source code is available here. The most relevant files are:
-OpenGL class (header / source)
-Main code (header / source)
Thx in advance if anyone can help me.
↧