How to stop glutviewer (opengl) from alvar lib?

I try to learn sth and I use opengl and alvar library. In alvar library I have glutviewer file that uses opengl library. I have sth like this (this is an example form alvar lib):

void * GlutViewer::glut_thread(void *lpThreadParameter)
{
qDebug()<<“glut_thread”;
//InitializeCriticalSection(&critical_section_items);

glutInit(&(Instance().a_argc), Instance().a_argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(Instance().width, Instance().height);

Instance().ar_window = glutCreateWindow(“AR”);
glutDisplayFunc(DrawAr);
glutSpecialFunc(KeyCallback);
glutPositionWindow(0, 0);

Instance().vr_window = glutCreateWindow(“VR”);
glutDisplayFunc(DrawVr);
glutPositionWindow(0, Instance().height);

glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);

glutMouseFunc(Mouse);
glutMotionFunc(Motion);

atexit(Exit);

glutMainLoop();
return 0;
}

Above function is call in start function:

void GlutViewer::Start(/parameters/)
{
// assign parameters

Instance().threads.create(glut_thread, 0); // alvar::Threads
}

My problem is that now it ends only when whole program ends. Does anyone know how to make it possible to end/kill/terminate that part of program without finishing whole program? I hope I write it clearly.

If you use FreeGLUT, you can use glutLeaveMainLoop() to terminate the main loop, causing glutMainLoop() to return. Or you can use your own main loop, calling glutMainLoopEvent() to process each event.

If you need more control than that, you’ll need to use a different toolkit (e.g. Qt, GTK, wxWidgets) or the platform’s native windowing API.

[QUOTE=GClements;1280115]If you use FreeGLUT, you can use glutLeaveMainLoop() to terminate the main loop, causing glutMainLoop() to return. Or you can use your own main loop, calling glutMainLoopEvent() to process each event.

If you need more control than that, you’ll need to use a different toolkit (e.g. Qt, GTK, wxWidgets) or the platform’s native windowing API.[/QUOTE]

Ok, I use freeGLUT instead a glut that I had. But I get error
“Unhandled exception at 0x553651fd in viewerTest.exe: 0xC0000005: Access violation reading location 0xfeeefef6.”
It shows that error in line with “return 0;” in glut_thread function

That may be an issue with this “alvar” library (I’m not familiar with it). Does it use the pointer returned from the thread function? You’re returning a null pointer, so if anything dereferences the pointer, you’ll get an access violation.

One thing to bear in mind is that if you’re creating a separate thread for the “viewer”, you should only be calling OpenGL or GLUT functions from that thread, not from the main thread.