mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 07:57:29 +00:00
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:
+9
-6
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user