Skip to content

Commit

Permalink
Add C->Lua protections to hs.canvas fadeOut:andDelete:withState. Clos…
Browse files Browse the repository at this point in the history
…es #HAMMERSPOON-BX
  • Loading branch information
cmsj committed Mar 28, 2022
1 parent 58f9773 commit 4b6a6a4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extensions/canvas/libcanvas.m
Original file line number Diff line number Diff line change
Expand Up @@ -955,15 +955,23 @@ - (void)fadeOut:(NSTimeInterval)fadeTime andDelete:(BOOL)deleteCanvas withState:
CGFloat alphaSetting = self.alphaValue ;
[NSAnimationContext beginGrouping];
__weak HSCanvasWindow *bself = self; // in ARC, __block would increase retain count
LSGCCanary canary = [skin createGCCanary];

[[NSAnimationContext currentContext] setDuration:fadeTime];
[[NSAnimationContext currentContext] setCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
// unlikely that bself will go to nil after this starts, but this keeps the warnings down from [-Warc-repeated-use-of-weak]
HSCanvasWindow *mySelf = bself ;
if (mySelf && (((HSCanvasView *)mySelf.contentView).selfRef != LUA_NOREF)) {
LuaSkin *bSkin = [LuaSkin sharedWithState:NULL] ;
_lua_stackguard_entry(bSkin.L);
HSCanvasView *myView = mySelf.contentView ;
myView.selfRef = [bSkin luaUnref:refTable ref:myView.selfRef] ;

if ([skin checkGCCanary:canary]) {
myView.selfRef = [bSkin luaUnref:refTable ref:myView.selfRef] ;
}
[skin destroyGCCanary:(LSGCCanary *)&canary];
_lua_stackguard_exit(bSkin.L);

// if (deleteCanvas) {
// LuaSkin *skin = [LuaSkin sharedWithState:NULL] ;
Expand Down

0 comments on commit 4b6a6a4

Please sign in to comment.