From 1398f4f828d70971964bf016d8b642d84af1a8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 5 Sep 2018 18:51:29 +0200 Subject: macOS: Release surfaces straight away when reconfiguring QCocoaGLContext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Simon Hausmann --- src/plugins/platforms/cocoa/qcocoaglcontext.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/plugins/platforms/cocoa/qcocoaglcontext.mm') 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]; -- cgit v1.2.3