Skip to content

Commit

Permalink
Add timely release of autorelease objects on the macOS platform. (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingpqi123 authored Jan 22, 2025
1 parent a53862a commit e5103ae
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/gpu/opengl/cgl/CGLDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@
if (glDevice) {
return std::static_pointer_cast<CGLDevice>(glDevice);
}
auto oldCGLContext = CGLGetCurrentContext();
if (oldCGLContext != cglContext) {
CGLSetCurrentContext(cglContext);
if (CGLGetCurrentContext() != cglContext) {
return nullptr;
@autoreleasepool {
auto oldCGLContext = CGLGetCurrentContext();
if (oldCGLContext != cglContext) {
CGLSetCurrentContext(cglContext);
if (CGLGetCurrentContext() != cglContext) {
return nullptr;
}
}
auto device = std::shared_ptr<CGLDevice>(new CGLDevice(cglContext));
device->externallyOwned = externallyOwned;
device->weakThis = device;
if (oldCGLContext != cglContext) {
CGLSetCurrentContext(oldCGLContext);
}
return device;
}
auto device = std::shared_ptr<CGLDevice>(new CGLDevice(cglContext));
device->externallyOwned = externallyOwned;
device->weakThis = device;
if (oldCGLContext != cglContext) {
CGLSetCurrentContext(oldCGLContext);
}
return device;
}

CGLDevice::CGLDevice(CGLContextObj cglContext) : GLDevice(cglContext) {
Expand Down Expand Up @@ -119,10 +121,12 @@
}

bool CGLDevice::onMakeCurrent() {
oldContext = CGLGetCurrentContext();
CGLRetainContext(oldContext);
[glContext makeCurrentContext];
return [NSOpenGLContext currentContext] == glContext;
@autoreleasepool {
oldContext = CGLGetCurrentContext();
CGLRetainContext(oldContext);
[glContext makeCurrentContext];
return [NSOpenGLContext currentContext] == glContext;
}
}

void CGLDevice::onClearCurrent() {
Expand Down

0 comments on commit e5103ae

Please sign in to comment.