Index: OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm
===================================================================
--- OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm (revision 10285)
+++ OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm (revision 10340)
@@ -20,7 +20,7 @@
 #include "DarwinUtils.h"
 
-//#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl;
-
-#define DEBUG_OUT(s) ;
+#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl;
+
+//#define DEBUG_OUT(s) ;
 
 static bool s_quit_requested = false;
@@ -389,6 +389,6 @@
 - (void) mouseMoved:(NSEvent*)theEvent 
 {
-    DEBUG_OUT("Mouse moved");
     NSPoint converted_point = [self getLocalPoint: theEvent];
+    DEBUG_OUT("Mouse moved" << converted_point.x << "/" << converted_point.y);
     _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y);
 }
@@ -606,4 +606,6 @@
     if (!_win) return;
     
+    DEBUG_OUT("middleMouseDown ");
+    
     NSPoint converted_point = [self getLocalPoint: theEvent];
     
@@ -621,4 +623,6 @@
 {
     if (!_win) return;
+    
+    DEBUG_OUT("extraMouseDown btn: " << button_number);
     
     NSPoint converted_point = [self getLocalPoint: theEvent];
@@ -1037,16 +1041,20 @@
     if (mbc) mbc->detachWindow(this);
     
-    if (_window) {
-        [_window close];
-        [_window release];
-    }
-    
     if (_view) {
         [_view setGraphicsWindowCocoa: NULL];
     }
+        
+    if (_window) {
+        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+        
+        // we have to close + release the window in the main-thread
+        
+        [_window performSelectorOnMainThread: @selector(close) withObject:NULL waitUntilDone: YES];
+        [_window performSelectorOnMainThread: @selector(release) withObject:NULL waitUntilDone: YES];
+        [pool release];
+    }
     
     _window = NULL;
-    _view = NULL;
-    
+    _view = NULL;    
 }
 
