mirror of
https://github.com/glfw/glfw.git
synced 2026-11-18 12:54:54 +00:00
Cocoa: Replace global autorelease pool with blocks
This is another small step towards having GLFW play nice with other toolkits sharing the same process, including AppKit. Any macOS platform function that touches Cocoa must now wrap itself in an autoreleasepool block. Since GLFW no longer provides an autoreleasepool outside of its functions, THIS MAY BREAK EXISTING CODE MIXING GLFW AND COCOA. Sorry! Please add your own autoreleasepool blocks as needed. Fixes #1107. Closes #1114.
This commit is contained in:
@@ -33,27 +33,37 @@
|
||||
|
||||
static void makeContextCurrentNSGL(_GLFWwindow* window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
if (window)
|
||||
[window->context.nsgl.object makeCurrentContext];
|
||||
else
|
||||
[NSOpenGLContext clearCurrentContext];
|
||||
|
||||
_glfwPlatformSetTls(&_glfw.contextSlot, window);
|
||||
|
||||
} // autoreleasepool
|
||||
}
|
||||
|
||||
static void swapBuffersNSGL(_GLFWwindow* window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
// ARP appears to be unnecessary, but this is future-proof
|
||||
[window->context.nsgl.object flushBuffer];
|
||||
} // autoreleasepool
|
||||
}
|
||||
|
||||
static void swapIntervalNSGL(int interval)
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
_GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
|
||||
|
||||
GLint sync = interval;
|
||||
[window->context.nsgl.object setValues:&sync
|
||||
forParameter:NSOpenGLContextParameterSwapInterval];
|
||||
|
||||
} // autoreleasepool
|
||||
}
|
||||
|
||||
static int extensionSupportedNSGL(const char* extension)
|
||||
@@ -80,11 +90,15 @@ static GLFWglproc getProcAddressNSGL(const char* procname)
|
||||
//
|
||||
static void destroyContextNSGL(_GLFWwindow* window)
|
||||
{
|
||||
@autoreleasepool {
|
||||
|
||||
[window->context.nsgl.pixelFormat release];
|
||||
window->context.nsgl.pixelFormat = nil;
|
||||
|
||||
[window->context.nsgl.object release];
|
||||
window->context.nsgl.object = nil;
|
||||
|
||||
} // autoreleasepool
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user