diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-09-05 18:51:29 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-09-10 09:03:36 +0000 |
commit | 1398f4f828d70971964bf016d8b642d84af1a8e1 (patch) | |
tree | c4c6ba731fc5ca9abec009d792b525c4030c39da /src/plugins/platforms/cocoa/qcocoaglcontext.mm | |
parent | 33b79ddc805b41ca4aad47be821508543721f534 (diff) |
macOS: Release surfaces straight away when reconfiguring QCocoaGLContext
Calling setView or update on NSOpenGLContext results in recreating the
internal GL surfaces of the view. Unfortunately there seems to be a
fixed amount of these surfaces available, so if we spin a loop where
we for some reason end up recreating them, we'll easily run out, and
lock up the whole window system:
thread #6, name = 'SwapThread'
frame #0: 0x00007fff7b45220a libsystem_kernel.dylib`mach_msg_trap + 10
frame #1: 0x00007fff7b451724 libsystem_kernel.dylib`mach_msg + 60
frame #2: 0x00007fff751c1675 SkyLight`SLSBindSurface + 247
frame #3: 0x00007fff5d9c4328 OpenGL`___lldb_unnamed_symbol29$$OpenGL + 255
frame #4: 0x00007fff6bf42c33 libGPUSupportMercury.dylib`gldAttachDrawable + 364
frame #5: 0x00007fff5d9e61e7 GLEngine`gliAttachDrawableWithOptions + 257
frame #6: 0x00007fff5d9c4bb0 OpenGL`___lldb_unnamed_symbol38$$OpenGL + 969
frame #7: 0x00007fff5d9c8b0e OpenGL`___lldb_unnamed_symbol57$$OpenGL + 82
frame #8: 0x00007fff5d9c8e55 OpenGL`CGLSetSurface + 330
frame #9: 0x00007fff50d0eb2c AppKit`NSOpenGLContextAttachOffScreenViewSurface + 352
This can happen e.g. when resizing the application, where AppKit itself spins
a loop where we don't end up back in QCocoaEventDispatcher::processEvents()
for each pass (where we do have a local pool). Or it can happen in the
render-loop of a render-thread that doesn't use the event dispatcher.
Change-Id: Iaf2f879dd01e3d807d0f35705ccc978dbc89036b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaglcontext.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaglcontext.mm | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index c90f093836..f11016679a 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -363,6 +363,11 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface) */ bool QCocoaGLContext::setDrawable(QPlatformSurface *surface) { + // Make sure any surfaces released during this process are deallocated + // straight away, otherwise we may run out of surfaces when spinning a + // render-loop that doesn't return to one of the outer pools. + QMacAutoReleasePool pool; + if (!surface || surface->surface()->surfaceClass() == QSurface::Offscreen) { // Clear the current drawable and reset the active window, so that GL // commands that don't target a specific FBO will not end up stomping @@ -393,6 +398,11 @@ static QMutex s_contextMutex; void QCocoaGLContext::update() { + // Make sure any surfaces released during this process are deallocated + // straight away, otherwise we may run out of surfaces when spinning a + // render-loop that doesn't return to one of the outer pools. + QMacAutoReleasePool pool; + QMutexLocker locker(&s_contextMutex); qCInfo(lcQpaOpenGLContext) << "Updating" << m_context << "for" << m_context.view; [m_context update]; |