Skip to content
This repository was archived by the owner on Mar 12, 2022. It is now read-only.

Commit 52a2bbc

Browse files
committed
prevent crash if screen disappears but it's hs.screen userdata still exists
1 parent a0c32ec commit 52a2bbc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: internal.m

+15-8
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ BOOL isScreenUUIDValid(NSString *theDisplay) {
1616
for (NSScreen *screen in [NSScreen screens]) {
1717
CGDirectDisplayID cgID = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue] ;
1818
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+
}
2527
}
2628
return isValid ;
2729
}
@@ -128,8 +130,13 @@ static int screenUUID(lua_State *L) {
128130
NSScreen *screen = (__bridge NSScreen*)*((void**)luaL_checkudata(L, 1, "hs.screen")) ;
129131
CGDirectDisplayID cgID = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue] ;
130132
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+
}
133140
return 1 ;
134141
}
135142

0 commit comments

Comments
 (0)