Subscribe: wednesday night / latest ramblings
Preview: wednesday night / latest ramblings

wednesday night

the latest ramblings

Updated: 2016-11-18T15:39:18Z


endRefreshing while decelerating


endRefreshing while decelerating
Sunday, February 2, 2014

i've spent all weekend fighting an annoying bug. if i import/sync some JSON into CoreData while my tableView is scrolling, it will halt abruptly, even if the MOC i'm doing the sync on uses private concurrency.

i spent 3 days debugging and optimizing the CoreData part:

  1. not saving parentContexts if no changes were made
  2. making sure fetchRequest queries were using indexes
  3. tweaking my algorithm to use one FetchRequest rather than two
  4. ...then splitting the FetchRequest into smaller batches

and so on. things were improved, and i'm happy with the fine-tuning to the syncing code, it still didn't fix the problem. the fetchRequests were taking less than .1 second, so the UI was not blocking on CoreData.

after adding some breakpoints, i finally found the culprit: calling -[UIRefreshControl endRefreshing] while the tableView is decelerating instantly causes it to stop accelerating. i coded up a quick test app, and found out that using -performSelector:withObject:afterDelay: solves the problem, as the selector won't be performed until after deceleration finishes:

$ $ $

Tweet or post a comment.

ScreenSharing hanging on Mavericks: a workaround


ScreenSharing hanging on Mavericks: a workaround
Saturday, November 30, 2013

i don't know why, but ScreenSharing doesn't work on my macbook air, it just hangs at startup. this is due to an exception thrown while a lock is held:

2013-11-30 17:55:31.602 Screen Sharing[34074:507] *** -[__NSSetM addObject:]: object cannot be nil 2013-11-30 17:55:31.630 Screen Sharing[34074:507] ( 0 CoreFoundation 0x00007fff8ddfa41c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff89e01e75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8dd19d66 -[__NSSetM addObject:] + 790 3 ScreenSharing 0x00007fff8fe58382 -[SSInputEventSourceCoordinator addSource:] + 69 4 CoreFoundation 0x00007fff8ddc8fcc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 5 CoreFoundation 0x00007fff8dcbcc5d _CFXNotificationPost + 2893 6 Foundation 0x00007fff94d854aa -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 7 AppKit 0x00007fff96129d0e -[NSApplication finishLaunching] + 440 8 AppKit 0x00007fff96129823 -[NSApplication run] + 128 9 AppKit 0x00007fff96114803 NSApplicationMain + 940 10 libdyld.dylib 0x00007fff8d0255fd start + 1 ) 2013-11-30 17:55:31.667 Screen Sharing[34074:507] *** -[NSLock lock]: deadlock ( '(null)') 2013-11-30 17:55:31.667 Screen Sharing[34074:507] *** Break on _NSLockError() to debug.

for whatever reason, it's passing nil to some thing when it should be passing a reference to the NSApplication. this can be worked around with a little lldb magic:

$ cat > ScreenSharing.lddb file '/System/Library/CoreServices/Screen Sharing' breakpoint set -o -a 0x00007fff8fe5837f breakpoint command add -o 'register write $rdx \`[NSApplication sharedApplication]\`' r $ lldb -s ScreenSharing.lddb Process 34102 stopped * thread #1: tid = 0xe812e, 0x00007fff8fe5837f ScreenSharing`-[SSInputEventSourceCoordinator addSource:] + 66, queue = ', stop reason = one-shot breakpoint 1 frame #0: 0x00007fff8fe5837f ScreenSharing`-[SSInputEventSourceCoordinator addSource:] + 66 ScreenSharing`-[SSInputEventSourceCoordinator addSource:] + 66: -> 0x7fff8fe5837f: callq *%r12 0x7fff8fe58382: movq (%rbx,%r15), %rdi 0x7fff8fe58386: movq -357651365(%rip), %rsi ; "unlock" 0x7fff8fe5838d: callq *%r12 (lldb) c Process 34102 resuming

this isn't ideal, but at least i can use screen sharing again. no idea why it works fine on my other macs, either.

$ $ $

Tweet or post a comment.