@@ -16,12 +16,14 @@ BOOL isScreenUUIDValid(NSString *theDisplay) {
16
16
for (NSScreen *screen in [NSScreen screens ]) {
17
17
CGDirectDisplayID cgID = [[[screen deviceDescription ] objectForKey: @" NSScreenNumber" ] unsignedIntValue ] ;
18
18
CFUUIDRef theUUID = CGDisplayCreateUUIDFromDisplayID (cgID) ;
19
- CFStringRef UUIDString = CFUUIDCreateString (kCFAllocatorDefault , theUUID) ;
20
- if (CFStringCompare ((__bridge CFStringRef )theDisplay, UUIDString, kCFCompareCaseInsensitive ) == kCFCompareEqualTo )
21
- isValid = YES ;
22
- CFRelease (UUIDString) ;
23
- CFRelease (theUUID) ;
24
- if (isValid) break ;
19
+ if (theUUID) {
20
+ CFStringRef UUIDString = CFUUIDCreateString (kCFAllocatorDefault , theUUID) ;
21
+ if (CFStringCompare ((__bridge CFStringRef )theDisplay, UUIDString, kCFCompareCaseInsensitive ) == kCFCompareEqualTo )
22
+ isValid = YES ;
23
+ CFRelease (UUIDString) ;
24
+ CFRelease (theUUID) ;
25
+ if (isValid) break ;
26
+ }
25
27
}
26
28
return isValid ;
27
29
}
@@ -128,8 +130,13 @@ static int screenUUID(lua_State *L) {
128
130
NSScreen *screen = (__bridge NSScreen *)*((void **)luaL_checkudata (L, 1 , " hs.screen" )) ;
129
131
CGDirectDisplayID cgID = [[[screen deviceDescription ] objectForKey: @" NSScreenNumber" ] unsignedIntValue ] ;
130
132
CFUUIDRef theUUID = CGDisplayCreateUUIDFromDisplayID (cgID) ;
131
- CFStringRef UUIDString = CFUUIDCreateString (kCFAllocatorDefault , theUUID) ;
132
- [[LuaSkin shared ] pushNSObject: (__bridge_transfer NSString *)UUIDString] ;
133
+ if (theUUID) {
134
+ CFStringRef UUIDString = CFUUIDCreateString (kCFAllocatorDefault , theUUID) ;
135
+ [[LuaSkin shared ] pushNSObject: (__bridge_transfer NSString *)UUIDString] ;
136
+ CFRelease (theUUID) ;
137
+ } else {
138
+ lua_pushnil (L) ;
139
+ }
133
140
return 1 ;
134
141
}
135
142
0 commit comments