Cocoa: Clean up context creation.
Make the fallback to creating an unshared context actually work by using correct [initWithFormat: ] code. Warn and return early on context creation failure instead of continuing and crashing. Change-Id: Ic88f419eaa717436aefc9c1da36c47e0ccb3e956 Task-number: QTBUG-47825 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
parent
1b459a8124
commit
ba94e26b8b
@ -146,19 +146,25 @@ QCocoaGLContext::QCocoaGLContext(const QSurfaceFormat &format, QPlatformOpenGLCo
|
||||
|
||||
QMacAutoReleasePool pool; // For the SG Canvas render thread
|
||||
|
||||
// create native context for the requested pixel format and share
|
||||
NSOpenGLPixelFormat *pixelFormat = static_cast <NSOpenGLPixelFormat *>(qcgl_createNSOpenGLPixelFormat(m_format));
|
||||
m_shareContext = share ? static_cast<QCocoaGLContext *>(share)->nsOpenGLContext() : nil;
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:m_shareContext];
|
||||
|
||||
m_context = [NSOpenGLContext alloc];
|
||||
[m_context initWithFormat:pixelFormat shareContext:m_shareContext];
|
||||
|
||||
// retry without sharing on context creation failure.
|
||||
if (!m_context && m_shareContext) {
|
||||
// try without shared context
|
||||
m_shareContext = nil;
|
||||
[m_context initWithFormat:pixelFormat shareContext:nil];
|
||||
m_context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
|
||||
if (m_context)
|
||||
qWarning("QCocoaGLContext: Falling back to unshared context.");
|
||||
}
|
||||
|
||||
// give up if we still did not get a native context
|
||||
[pixelFormat release];
|
||||
if (!m_context) {
|
||||
qWarning("QCocoaGLContext: Failed to create context.");
|
||||
return;
|
||||
}
|
||||
|
||||
const GLint interval = format.swapInterval() >= 0 ? format.swapInterval() : 1;
|
||||
[m_context setValues:&interval forParameter:NSOpenGLCPSwapInterval];
|
||||
|
Loading…
x
Reference in New Issue
Block a user