This small program crashes when executing the return 0; line. #include <stdio.h> #include <GL/glew.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <GL/glext.h> int main(int argc, char **argv) { glutInit(&argc, argv); glutCreateWindow("GLUT"); glewInit(); printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION)); fprintf(stdout, "Exiting...\n"); fflush(stdout); return 0; } To reproduce you must install virtualbox-ose-additions with opengl enabled and compile (cc -I/usr/local/include -L/usr/local/lib -o testegl testegl.c -lGL -lGLEW -lGLU -lglut) and run this program. After debugging gdb say that the exception is raised on line 679 of file /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/GuestHost/OpenGL/util/hash.c void *crHashtableSearch( const CRHashTable *h, unsigned long key ) { unsigned int index = crHash( key ); CRHashNode *temp; #ifdef CHROMIUM_THREADSAFE bug is here =======> crLockMutex((CRmutex *)&h->mutex); #endif for ( temp = h->buckets[index]; temp; temp = temp->next ) { if ( temp->key == key ) break; } #ifdef CHROMIUM_THREADSAFE crUnlockMutex((CRmutex *)&h->mutex); #endif if ( !temp ) { return NULL; } return temp->data; }
(gdb) backtrace #0 check_and_init_mutex (mutex=0x20c8, m=0x7fffffffe650) at /usr/src/lib/libthr/thread/thr_mutex.c:588 #1 0x0000000802923506 in __pthread_mutex_lock (mutex=0x20c8) at /usr/src/lib/libthr/thread/thr_mutex.c:743 #2 0x0000000801e531f1 in crHashtableSearch (h=0x0, key=56623106) at /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/GuestHost/OpenGL/util/hash.c:679 #3 0x000000080088f1cb in glXMakeCurrent (dpy=0x80481f000, drawable=56623106, ctx=0x1f4) at /usr/ports/emulators/virtualbox-ose-additions/work/VirtualBox-5.1.8/src/VBox/Additions/common/crOpenGL/glx.c:694 #4 0x00000008010ce5be in fgSetWindow () from /usr/local/lib/libglut.so.3 #5 0x00000008010cc44c in fgDestroyWindow () from /usr/local/lib/libglut.so.3 #6 0x00000008010cc895 in fgDestroyStructure () from /usr/local/lib/libglut.so.3 #7 0x00000008010c9841 in fgDeinitialize () from /usr/local/lib/libglut.so.3 #8 0x0000000801b9add6 in __cxa_finalize (dso=<value optimized out>) at /usr/src/lib/libc/stdlib/atexit.c:237 #9 0x0000000801b2a141 in exit (status=0) at /usr/src/lib/libc/stdlib/exit.c:72 #10 0x0000000000400976 in _start () #11 0x0000000800622000 in ?? () #12 0x0000000000000000 in ?? ()
Oracle guy confirms that this occurs on Linux also.
This version of the program do not shows the bug. Looks related with a race condition when a call to glutDestroyWindow is missing. #include <stdio.h> #include <GL/glew.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <GL/glext.h> int main(int argc, char **argv) { int win; glutInit(&argc, argv); win = glutCreateWindow("GLUT"); glewInit(); printf("OpenGL version supported by this platform (%s): \n", glGetString(GL_VERSION)); glutDestroyWindow(win); fprintf(stdout, "Exiting...\n"); fflush(stdout); return 0; }
I think that this is related with application bad code because if add glutDestroyWindow to close the window before exit the program finishes fine.