Glsl Trouble when threaded (Win32)

Hello,

I’m experiencing trouble when calling “glCreateProgramObjectARB()” from a thread, made by CreateThread.

Sample code to reproduce:

void crashfunc() {
DWORD test = glCreateProgramObjectARB();
_asm push test // do some stuff so the compiler doenst get rid of it
_asm pop eax
}

void main() {
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CrashFunc, 0, 0, 0);
while(true){Sleep(100);}
}

The program crashes though before it reaches ‘asm push test’.
I’ve traced the problem; and it appears that the FS:[0xEF4] register contains 0…

aka, when in thread, glCreateProgramObjectARB gets called:
mov eax, FS:[0xEF4]; eax = 0

eax is then used as pointer to jmp to the func. This leads to an invalid pointer exception.

This is all occurs in the ATI userland wrapper…
I can apply some hackery, but this isn’t appreciated as this code might be executed at nvidia cards…

On windows you have to ensure the thread has a current OpenGL context before issuing any OpenGL calls. This is achived in the same way when first creating the window - by using wglMakeCurrent API call.

Also you are calling an extension function, so you have to call wglGetProcAddress to get the function pointer. And if you’re using a separate context in your main and worker thread you have to be careful to use the same pixel format for both contexts or you have to maintain separate function pointers in each thread.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.