From d416ebc78ce80cbab43051282d0c533dd0aacf24 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 26 Apr 2011 12:05:57 +0000 Subject: [PATCH] From Craig Bosma,"Please find attached a fix for shared contexts on OS X, with the Cocoa backend. The NSOpenGLContext* _context member of GraphicsHandleCocoa was never set on successfully creation, so even if the dynamic_cast to GraphicsHandleCocoa succeeds, we get a bogus (NULL) pointer on retrieving the actual NSOpenGLContext* (line 1013). This should fix the problem, as well as cause GraphicsWindowCocoa to report the correct name "GraphicsWindowCarbon" -> "GraphicsWindowCocoa". " --- include/osgViewer/api/Cocoa/GraphicsWindowCocoa | 2 +- src/osgViewer/GraphicsWindowCocoa.mm | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa index 076fedb84..54510c074 100644 --- a/include/osgViewer/api/Cocoa/GraphicsWindowCocoa +++ b/include/osgViewer/api/Cocoa/GraphicsWindowCocoa @@ -85,7 +85,7 @@ class GraphicsWindowCocoa : public osgViewer::GraphicsWindow, public osgViewer:: virtual bool isSameKindAs(const Object* object) const { return dynamic_cast(object)!=0; } virtual const char* libraryName() const { return "osgViewer"; } - virtual const char* className() const { return "GraphicsWindowCarbon"; } + virtual const char* className() const { return "GraphicsWindowCocoa"; } virtual bool valid() const { return _valid; } diff --git a/src/osgViewer/GraphicsWindowCocoa.mm b/src/osgViewer/GraphicsWindowCocoa.mm index 94e1eaa8a..ea986eb81 100644 --- a/src/osgViewer/GraphicsWindowCocoa.mm +++ b/src/osgViewer/GraphicsWindowCocoa.mm @@ -1020,6 +1020,10 @@ bool GraphicsWindowCocoa::realizeImplementation() OSG_WARN << "GraphicsWindowCocoa::realizeImplementation :: could not create context" << std::endl; return false; } + + // set graphics handle for shared usage + setNSOpenGLContext(_context); + GraphicsWindowCocoaGLView* theView = [[ GraphicsWindowCocoaGLView alloc ] initWithFrame:[ _window frame ] ]; [theView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable) ]; [theView setGraphicsWindowCocoa: this];