Skip to content

Commit 924298a

Browse files
zarvoxpiedar
authored andcommitted
Allow micview to exit cleanly on Linux (#527)
This change fixes a bug where micview would hang when the user presses 'q' to exit, and you'd have to kill -9 the process to make the window go away. On Linux, with at least the radeon graphics driver, glutCreateWindow appears to spawn several child threads for shaders, a disk cache, and something else: si_shader:0 si_shader:1 si_shader:2 si_shader:3 disk_cache:0 radeon_cs:0 These threads appear to keep the process as a whole from exiting when pthread_exit() is called. The solution is to call glutDestroyWindow(), which will cause glutMainLoop() to return, which causes main() to return cleanly.
1 parent 4d2fede commit 924298a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

examples/micview.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
pthread_t freenect_thread;
4141
volatile int die = 0;
4242

43+
int window;
44+
4345
static freenect_context* f_ctx;
4446
static freenect_device* f_dev;
4547

@@ -149,7 +151,8 @@ void Reshape(int w, int h) {
149151
void Keyboard(unsigned char key, int x, int y) {
150152
if(key == 'q') {
151153
die = 1;
152-
pthread_exit(NULL);
154+
pthread_join(freenect_thread, NULL);
155+
glutDestroyWindow(window);
153156
}
154157
if(key == 32) {
155158
paused = !paused;
@@ -205,7 +208,7 @@ int main(int argc, char** argv) {
205208
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA );
206209
glutInitWindowSize(800, 600);
207210
glutInitWindowPosition(0, 0);
208-
glutCreateWindow("Microphones");
211+
window = glutCreateWindow("Microphones");
209212
glClearColor(0.0, 0.0, 0.0, 0.0);
210213
glEnable(GL_BLEND);
211214
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

0 commit comments

Comments
 (0)