ui/app: (macOS) destroy the GL context correctly

The NSOpenGLView owns the NSOpenGLContext so we can't just CFRelease
the context. Use [NSOpenGLView releaseGLContext] instead.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-07-20 15:47:02 +02:00
parent 0b6e6c58dd
commit 05f0c3e22a
3 changed files with 15 additions and 6 deletions
+9 -6
View File
@@ -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
}
+1
View File
@@ -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);
+5
View File
@@ -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];
}