mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +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"
|
import "C"
|
||||||
|
|
||||||
type context struct {
|
type context struct {
|
||||||
c *gl.Functions
|
c *gl.Functions
|
||||||
ctx C.CFTypeRef
|
ctx C.CFTypeRef
|
||||||
|
view C.CFTypeRef
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -31,10 +32,12 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newContext(w *window) (*context, error) {
|
func newContext(w *window) (*context, error) {
|
||||||
ctx := C.gio_contextForView(w.contextView())
|
view := w.contextView()
|
||||||
|
ctx := C.gio_contextForView(view)
|
||||||
c := &context{
|
c := &context{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
c: new(gl.Functions),
|
c: new(gl.Functions),
|
||||||
|
view: view,
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@@ -47,7 +50,7 @@ func (c *context) Release() {
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
C.gio_clearCurrentContext()
|
C.gio_clearCurrentContext()
|
||||||
C.CFRelease(c.ctx)
|
C.gio_clearGLContext(c.view)
|
||||||
c.ctx = 0
|
c.ctx = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createGLView(void);
|
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_createGLView(void);
|
||||||
__attribute__ ((visibility ("hidden"))) CFTypeRef gio_contextForView(CFTypeRef viewRef);
|
__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_makeCurrentContext(CFTypeRef ctx);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_flushContextBuffer(CFTypeRef ctx);
|
__attribute__ ((visibility ("hidden"))) void gio_flushContextBuffer(CFTypeRef ctx);
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_clearCurrentContext(void);
|
__attribute__ ((visibility ("hidden"))) void gio_clearCurrentContext(void);
|
||||||
|
|||||||
@@ -143,6 +143,11 @@ CFTypeRef gio_contextForView(CFTypeRef viewRef) {
|
|||||||
return (__bridge CFTypeRef)view.openGLContext;
|
return (__bridge CFTypeRef)view.openGLContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gio_clearGLContext(CFTypeRef viewRef) {
|
||||||
|
NSOpenGLView *view = (__bridge NSOpenGLView *)viewRef;
|
||||||
|
[view clearGLContext];
|
||||||
|
}
|
||||||
|
|
||||||
void gio_clearCurrentContext(void) {
|
void gio_clearCurrentContext(void) {
|
||||||
[NSOpenGLContext clearCurrentContext];
|
[NSOpenGLContext clearCurrentContext];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user