app: [macOS] move destruction to NSView.dealloc

The dealloc method is where we're guaranteed the NSView is no longer
used anywhere.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-12-13 18:21:48 -06:00
parent 1527e91a02
commit 5e5d164929
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -869,14 +869,13 @@ func gio_onAttached(h C.uintptr_t, attached C.int) {
} }
} }
//export gio_onClose //export gio_onDestroy
func gio_onClose(h C.uintptr_t) { func gio_onDestroy(h C.uintptr_t) {
w := windowFor(h) w := windowFor(h)
w.ProcessEvent(DestroyEvent{}) w.ProcessEvent(DestroyEvent{})
w.displayLink.Close() w.displayLink.Close()
w.displayLink = nil w.displayLink = nil
cgo.Handle(h).Delete() cgo.Handle(h).Delete()
C.CFRelease(w.view)
w.view = 0 w.view = 0
} }
@@ -927,6 +926,8 @@ func newWindow(win *callbacks, options []Option) {
return return
} }
window := C.gio_createWindow(w.view, 0, 0, 0, 0, 0, 0) window := C.gio_createWindow(w.view, 0, 0, 0, 0, 0, 0)
// Release our reference now that the NSWindow has it.
C.CFRelease(w.view)
w.updateWindowMode() w.updateWindowMode()
w.Configure(options) w.Configure(options)
if nextTopLeft.x == 0 && nextTopLeft.y == 0 { if nextTopLeft.x == 0 && nextTopLeft.y == 0 {
+3 -3
View File
@@ -90,9 +90,6 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
} }
- (void)viewDidMoveToWindow { - (void)viewDidMoveToWindow {
gio_onAttached(self.handle, self.window != nil ? 1 : 0); gio_onAttached(self.handle, self.window != nil ? 1 : 0);
if (self.window == nil) {
gio_onClose(self.handle);
}
} }
- (void)mouseDown:(NSEvent *)event { - (void)mouseDown:(NSEvent *)event {
handleMouse(self, event, MOUSE_DOWN, 0, 0); handleMouse(self, event, MOUSE_DOWN, 0, 0);
@@ -205,6 +202,9 @@ static void handleMouse(GioView *view, NSEvent *event, int typ, CGFloat dx, CGFl
- (void)applicationDidHide:(NSNotification *)notification { - (void)applicationDidHide:(NSNotification *)notification {
gio_onHide(self.handle); gio_onHide(self.handle);
} }
- (void)dealloc {
gio_onDestroy(self.handle);
}
@end @end
// Delegates are weakly referenced from their peers. Nothing // Delegates are weakly referenced from their peers. Nothing