Fix Invalid Drawable error when using createWindowContainer on Mac.

You are not supposed to call NSOpenGLContext -setView: for a view that
has not yet called drawRect.  Doing this would result in a invalid
drawable error.

Similar to 4.8 commit cd2a51a66f

Change-Id: Ibb2300a8c6fe52f786f813987e93d4a3dc145366
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
Chris Meyer 2013-09-09 14:00:18 -07:00 committed by The Qt Project
parent c9c435179e
commit 04325bdd26
2 changed files with 7 additions and 3 deletions

View File

@ -70,6 +70,7 @@ QT_END_NAMESPACE
Qt::KeyboardModifiers currentWheelModifiers; Qt::KeyboardModifiers currentWheelModifiers;
bool m_subscribesForGlobalFrameNotifications; bool m_subscribesForGlobalFrameNotifications;
QCocoaGLContext *m_glContext; QCocoaGLContext *m_glContext;
bool m_drawRectHasBeenCalled;
bool m_shouldSetGLContextinDrawRect; bool m_shouldSetGLContextinDrawRect;
} }

View File

@ -87,6 +87,7 @@ static QTouchDevice *touchDevice = 0;
m_sendKeyEvent = false; m_sendKeyEvent = false;
m_subscribesForGlobalFrameNotifications = false; m_subscribesForGlobalFrameNotifications = false;
m_glContext = 0; m_glContext = 0;
m_drawRectHasBeenCalled = false;
m_shouldSetGLContextinDrawRect = false; m_shouldSetGLContextinDrawRect = false;
currentCustomDragTypes = 0; currentCustomDragTypes = 0;
m_sendUpAsRightButton = false; m_sendUpAsRightButton = false;
@ -153,9 +154,9 @@ static QTouchDevice *touchDevice = 0;
- (void) setQCocoaGLContext:(QCocoaGLContext *)context - (void) setQCocoaGLContext:(QCocoaGLContext *)context
{ {
m_glContext = context; m_glContext = context;
[m_glContext->nsOpenGLContext() setView:self]; if (m_drawRectHasBeenCalled) {
if (![m_glContext->nsOpenGLContext() view]) { [m_glContext->nsOpenGLContext() setView:self];
//was unable to set view } else {
m_shouldSetGLContextinDrawRect = true; m_shouldSetGLContextinDrawRect = true;
} }
@ -392,6 +393,8 @@ static QTouchDevice *touchDevice = 0;
m_shouldSetGLContextinDrawRect = false; m_shouldSetGLContextinDrawRect = false;
} }
m_drawRectHasBeenCalled = true;
if (!m_backingStore) if (!m_backingStore)
return; return;