diff mbox series

[v2,1/2] ui/cocoa: Minor fixes to CALayer based cursors

Message ID 20240625134931.92279-2-phil@philjordan.eu (mailing list archive)
State New, archived
Headers show
Series ui/cocoa: Adds native absolute pointer support | expand

Commit Message

Phil Dennis-Jordan June 25, 2024, 1:49 p.m. UTC
This change fixes some object lifetime issues. (Unreleased reference
counts)

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 ui/cocoa.m | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index 06ca114800..cca987eac7 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -395,6 +395,13 @@  - (void) dealloc
         CFRelease(eventsTap);
     }
 
+    if (cursor) {
+        cursor_unref(cursor);
+        cursor = NULL;
+    }
+
+    [cursorLayer release];
+    cursorLayer = nil;
     [super dealloc];
 }
 
@@ -474,6 +481,7 @@  - (void)setCursor:(QEMUCursor *)given_cursor
 
     bounds.size.width = cursor->width;
     bounds.size.height = cursor->height;
+    CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
 
     provider = CGDataProviderCreateWithData(
         NULL,
@@ -488,7 +496,7 @@  - (void)setCursor:(QEMUCursor *)given_cursor
         8, //bitsPerComponent
         32, //bitsPerPixel
         cursor->width * 4, //bytesPerRow
-        CGColorSpaceCreateWithName(kCGColorSpaceSRGB), //colorspace
+        color_space, //colorspace
         kCGBitmapByteOrder32Little | kCGImageAlphaFirst, //bitmapInfo
         provider, //provider
         NULL, //decode
@@ -497,6 +505,7 @@  - (void)setCursor:(QEMUCursor *)given_cursor
     );
 
     CGDataProviderRelease(provider);
+    CGColorSpaceRelease(color_space);
     [CATransaction begin];
     [CATransaction setDisableActions:YES];
     [cursorLayer setBounds:bounds];