View Full Version : Threads: segmentation fail with GL-functions calls
07-10-2011, 08:21 AM
I'm coding via Debian 6.0.1, C (without C++).
I create a new thread in my program via "pthread_create()" function. In this new thread I want to doing smth via GL-functions. For example, I tried to call glGetFloat() function. But I had segmentation fail there. So, any gl<...> functions make me the same error.
glu<...> or glut<...> functions are working correctly in the threads.
What's can be wrong there?
Best regards, Serge.
07-10-2011, 08:29 AM
Something is not clear... How can glu functions work, while gl don't?
glu is just a wrapper around gl. You have to make GL context current for the calling thread. Be aware that GL context can be current in one thread only (one at the time).
07-11-2011, 10:58 AM
I have this main function in my program:
int main (int argc, char *argv)
if(pthread_getschedparam(pthread_self(), &Threads_Init_Policy, &Threads_Init_Schedule_Params) != 0)
if(pthread_create(&Thread_Init, &Threads_Init_Attribute, (void *(*)(void*))func_thread, 0) != 0)
And this for the thread:
So, I can transfer this code to my thread function from my main function:
Also, I can write here something like this (for the glu functions):
int *viewport = (int*)malloc(sizeof(int)*4);
double *mvmatrix = (double*)malloc(sizeof(double)*16);
double *projmatrix = (double*)malloc(sizeof(double)*16);
gluProject(0.0, 0.0, 0.0,
mvmatrix, projmatrix, viewport,
&l_x, &l_y, &l_z
And it works fine. But if I call some gl function in func_thread(), there will be the segmentation fail. Ex., glShadeModel(GL_SMOOTH);
07-12-2011, 08:35 AM
In the first thread, you need to make the GL context non current with a call to glXMakeCurrent. Put NULL for the GL render context.
Now, on the secondary thread, you can make it current.
07-13-2011, 09:24 AM
V-man, I have just read info about glXMakeCurrent. Do I understand it right: I need to make Display, XtAppContext, XVisualInfo variables, set some int variable as ScreenID... Then set Display with XtDisplay... Then use glXChooseVisual...And only this moment set glxcontext...
Is that absolutly another technology to setup an OpenGL canvas?
I just create glutWindow (code in the post #3), and it almost makes me happy.
Or if I want to work with threads, I need to make that big (see the top of the post) setup anyway?
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.