ios - CoreMotion crash(iPad-only) on invoking stopDeviceMotionUpdates -


we have instance of cmmotionmanager in our app use sensor updates @ frequency of 5hz. following code use start motion updates:

[self.motionmanager startdevicemotionupdatesusingreferenceframe: cmattitudereferenceframexmagneticnorthzvertical toqueue:operationqueue withhandler:^(cmdevicemotion *motion, nserror *error) { if (!error) {     [self dosomethingwithmotion:motion]; } else { ... } 

the above method invoked on main thread.

now, once done our task, stop motion updates calling following method, again on main thread :

- (void)stopmotionupdates {     // might called on concurrent threads.     // better using sync block + make idempotent     @synchronized(self) {         if (_motionmanager.devicemotionactive) {             [_motionmanager stopdevicemotionupdates];             _prevpoint = nil;         }     } } 

the issue facing stopmotionupdates crashes, too, in ipads. have tested extensively on iphones , ipads different os versions , crash on ipads (mini 1,2 , retina/non-retina) both ios7 , ios8. also, cannot reproduce crash on ipads use testing, few. following crash logs main , crashed thread:

thread : com.apple.main-thread 0  libsystem_kernel.dylib         0x00000001935f1cdc semaphore_wait_trap + 8 1  libdispatch.dylib              0x00000001934fbb3c _dispatch_semaphore_wait_slow + 252 2  coremotion                     0x0000000186bf67d4 (null) 3  coremotion                     0x0000000186be3698 (null) 4  myapp                          0x00000001002f7434 -[myappmotionmanager stopmotionupdates] ... ... 12 myapp                          0x00000001002e94f8 __getdispatchtimer_block_invoke 13 libdispatch.dylib              0x00000001934f3fd4 _dispatch_client_callout + 16 14 libdispatch.dylib              0x00000001934f5b90 _dispatch_source_invoke + 500 15 libdispatch.dylib              0x00000001934f7180 _dispatch_main_queue_callback_4cf + 244 16 corefoundation                 0x00000001864fec2c __cfrunloop_is_servicing_the_main_dispatch_queue__ + 12 17 corefoundation                 0x00000001864fcf6c __cfrunlooprun + 1452 18 corefoundation                 0x000000018643dc20 cfrunlooprunspecific + 452 19 graphicsservices               0x000000018c0ddc0c gseventrunmodal + 168 20 uikit                          0x000000018956efdc uiapplicationmain + 1156 21 myapp                          0x00000001000c9850 main (main.m:14) 22 libdyld.dylib                  0x000000019350faa0 start + 4  exc_breakpoint unknown @ 0x0000000186c257ac thread : crashed: thread 0  coremotion                     0x0000000186c257ac (null) + 110504 1  coremotion                     0x0000000186c25774 (null) + 110448 2  coremotion                     0x0000000186bf3c84 (null) 3  coremotion                     0x0000000186bf67ec (null) 4  coremotion                     0x0000000186bf3b80 (null) 5  coremotion                     0x0000000186c24c48 (null) + 107588 6  coremotion                     0x0000000186bf67ec (null) 7  coremotion                     0x0000000186c24ba4 (null) + 107424 8  coremotion                     0x0000000186be3b9c (null) 9  coremotion                     0x0000000186bf6860 (null) 10 corefoundation                 0x00000001864ff680 __cfrunloop_is_calling_out_to_a_block__ + 20 11 corefoundation                 0x00000001864fe838 __cfrunloopdoblocks + 300 12 corefoundation                 0x00000001864fd0a4 __cfrunlooprun + 1764 13 corefoundation                 0x000000018643dc20 cfrunlooprunspecific + 452 14 corefoundation                 0x00000001864932a8 cfrunlooprun + 112 15 coremotion                     0x0000000186bf653c (null) 16 libsystem_pthread.dylib        0x000000019368be1c _pthread_body + 168 17 libsystem_pthread.dylib        0x000000019368bd74 _pthread_body 

since reference self in motion update handler block, object shouldn't deallocated till entire queue flushed. appreciated :)

you might overloading main thread.

  • as rule of thumb, should never on main thread takes more or second.

  • the main thread responsible running user interface. if block main thread significant amount of time, user interface becomes unacceptably unresponsive.

  • watchdog — in order keep user interface responsive, ios includes watchdog mechanism. if application fails respond user interface events (launch, suspend, resume, terminate) in time or operation takes little bit more time on main thread watchdog kill application. amount of time watchdog gives not formally documented, it's less.

  • any such operation must done on background thread , using

    • dispatch_async

    • nsoperationqueue

    • performselectorinbackground

hope helps.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -