diff --git a/ui/app/gl_macos.go b/ui/app/gl_macos.go index 1bc332e7..7805d2a1 100644 --- a/ui/app/gl_macos.go +++ b/ui/app/gl_macos.go @@ -20,8 +20,9 @@ import ( import "C" type context struct { - c *gl.Functions - ctx C.CFTypeRef + c *gl.Functions + ctx C.CFTypeRef + view C.CFTypeRef } func init() { @@ -31,10 +32,12 @@ func init() { } func newContext(w *window) (*context, error) { - ctx := C.gio_contextForView(w.contextView()) + view := w.contextView() + ctx := C.gio_contextForView(view) c := &context{ - ctx: ctx, - c: new(gl.Functions), + ctx: ctx, + c: new(gl.Functions), + view: view, } return c, nil } @@ -47,7 +50,7 @@ func (c *context) Release() { c.Lock() defer c.Unlock() C.gio_clearCurrentContext() - C.CFRelease(c.ctx) + C.gio_clearGLContext(c.view) c.ctx = 0 } diff --git a/ui/app/gl_macos.h b/ui/app/gl_macos.h index f41c0cbc..a396fdb4 100644 --- a/ui/app/gl_macos.h +++ b/ui/app/gl_macos.h @@ -2,6 +2,7 @@ __attribute__ ((visibility ("hidden"))) CFTypeRef gio_createGLView(void); __attribute__ ((visibility ("hidden"))) CFTypeRef gio_contextForView(CFTypeRef viewRef); +__attribute__ ((visibility ("hidden"))) void gio_clearGLContext(CFTypeRef viewRef); __attribute__ ((visibility ("hidden"))) void gio_makeCurrentContext(CFTypeRef ctx); __attribute__ ((visibility ("hidden"))) void gio_flushContextBuffer(CFTypeRef ctx); __attribute__ ((visibility ("hidden"))) void gio_clearCurrentContext(void); diff --git a/ui/app/gl_macos.m b/ui/app/gl_macos.m index fa317191..4741a45d 100644 --- a/ui/app/gl_macos.m +++ b/ui/app/gl_macos.m @@ -143,6 +143,11 @@ CFTypeRef gio_contextForView(CFTypeRef viewRef) { return (__bridge CFTypeRef)view.openGLContext; } +void gio_clearGLContext(CFTypeRef viewRef) { + NSOpenGLView *view = (__bridge NSOpenGLView *)viewRef; + [view clearGLContext]; +} + void gio_clearCurrentContext(void) { [NSOpenGLContext clearCurrentContext]; }