From f80033d89223aa2040dd1912ed72d4b3cfee1bfa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 May 2009 14:09:16 +0000 Subject: [PATCH] From Stephan Huber, "attached you'll find a small fix for GrphicsWindowCocoa. There was a bug with certain key-strokes, which led to a crash." --- src/osgViewer/GraphicsWindowCocoa.mm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 41dea46eb..8c92c0592 100755 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -669,9 +669,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) if (!_win) return; NSString* chars = [theEvent charactersIgnoringModifiers]; - unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask) ); - // std::cout << "key dn: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; - _win->getEventQueue()->keyPress( remapCocoaKey(keyCode), [theEvent timestamp]); + if ((chars) && ([chars length] > 0)) { + unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask) ); + // std::cout << "key dn: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; + _win->getEventQueue()->keyPress( remapCocoaKey(keyCode), [theEvent timestamp]); + } } @@ -680,9 +682,11 @@ static NSRect convertToQuartzCoordinates(const NSRect& rect) if (!_win) return; NSString* chars = [theEvent charactersIgnoringModifiers]; - unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask)); - // std::cout << "key up: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; - _win->getEventQueue()->keyRelease( remapCocoaKey(keyCode), [theEvent timestamp]); + if ((chars) && ([chars length] > 0)) { + unsigned int keyCode = remapCocoaKey([chars characterAtIndex:0], ([theEvent modifierFlags] & NSFunctionKeyMask)); + // std::cout << "key up: " <<[chars characterAtIndex:0] << "=" << keyCode << std::endl; + _win->getEventQueue()->keyRelease( remapCocoaKey(keyCode), [theEvent timestamp]); + } }