Show
Ignore:
Timestamp:
06/12/09 12:00:08 (4 years ago)
Author:
robert
Message:

From Stephan Huber, "here are some small fixes/enahncements for the cocoa backend to allow
proper functioning when running the osgViewer run-loop in a secondary
thread (e.g. when embedding GraphicsWindowCocoa?-windows in a full blown
cocoa application).

OS X is picky when you want to change the user-interface from another
thread than the main thread, not all UI stuff is thread-safe. So now
window closes and showing / hiding the menu bar is done in the main
thread via Cocoa's performSelectorOnMainThread-mechanism.

These changes don't affect the normal osgViewer usage pattern."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgViewer/GraphicsWindowCocoa.mm

    r10285 r10340  
    2020#include "DarwinUtils.h" 
    2121 
    22 //#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl; 
    23  
    24 #define DEBUG_OUT(s) ; 
     22#define DEBUG_OUT(s) std::cout << "GraphicsWindowCocoa :: " << s << std::endl; 
     23 
     24//#define DEBUG_OUT(s) ; 
    2525 
    2626static bool s_quit_requested = false; 
     
    389389- (void) mouseMoved:(NSEvent*)theEvent  
    390390{ 
    391     DEBUG_OUT("Mouse moved"); 
    392391    NSPoint converted_point = [self getLocalPoint: theEvent]; 
     392    DEBUG_OUT("Mouse moved" << converted_point.x << "/" << converted_point.y); 
    393393    _win->getEventQueue()->mouseMotion(converted_point.x, converted_point.y); 
    394394} 
     
    606606    if (!_win) return; 
    607607     
     608    DEBUG_OUT("middleMouseDown "); 
     609     
    608610    NSPoint converted_point = [self getLocalPoint: theEvent]; 
    609611     
     
    621623{ 
    622624    if (!_win) return; 
     625     
     626    DEBUG_OUT("extraMouseDown btn: " << button_number); 
    623627     
    624628    NSPoint converted_point = [self getLocalPoint: theEvent]; 
     
    10371041    if (mbc) mbc->detachWindow(this); 
    10381042     
    1039     if (_window) { 
    1040         [_window close]; 
    1041         [_window release]; 
    1042     } 
    1043      
    10441043    if (_view) { 
    10451044        [_view setGraphicsWindowCocoa: NULL]; 
    10461045    } 
     1046         
     1047    if (_window) { 
     1048        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
     1049         
     1050        // we have to close + release the window in the main-thread 
     1051         
     1052        [_window performSelectorOnMainThread: @selector(close) withObject:NULL waitUntilDone: YES]; 
     1053        [_window performSelectorOnMainThread: @selector(release) withObject:NULL waitUntilDone: YES]; 
     1054        [pool release]; 
     1055    } 
    10471056     
    10481057    _window = NULL; 
    1049     _view = NULL; 
    1050      
     1058    _view = NULL;     
    10511059} 
    10521060