Hello I noticed sporadic crashes on the main thread when terminating a call with video enabled on iOS, this happens maybe once in ten tries. I noticed that in all crashes the pjsip thread is at the ios_stream_destroy() function in ios_dev.m at the pj_pool_release(stream->pool); line. This leads me to believe that the crash is caused when the renderer view tries to draw something on screen but the allocation pool where that specific frame is stored has been deallocated. I managed to reduce the crashes to a minimum by updating ios_dev.m and performing the [prev_layer removeFromSuperlayer]; and [view removeFromSuperview]; operations synchronously on the main thread. It seems that this prevents the crashes from happening. Has anyone encountered these kind of crashes when dealing with video? Is there another way to fix it? Thanks! Below you can find the relevant stack trace. * thread #1: tid = 0x34f50c, 0x000000018453bf10 CoreGraphics`CGBlt_swapBytes + 328, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10afd4038) frame #0: 0x000000018453bf10 CoreGraphics`CGBlt_swapBytes + 328 frame #1: 0x000000018453bd24 CoreGraphics`img_raw_read + 2016 frame #2: 0x00000001845b02e8 CoreGraphics`img_alphamerge_read + 564 frame #3: 0x0000000184536ff4 CoreGraphics`img_data_lock + 5988 frame #4: 0x0000000184534e90 CoreGraphics`CGSImageDataLock + 140 frame #5: 0x0000000194c5d670 libRIP.A.dylib`ripc_AcquireImage + 732 frame #6: 0x0000000194c5ca7c libRIP.A.dylib`ripc_DrawImage + 620 frame #7: 0x00000001845a1884 CoreGraphics`CGContextDrawImageWithOptions + 456 frame #8: 0x0000000185a28a4c QuartzCore`CA::Render::(anonymous namespace)::create_image_by_rendering(CGImage*, CGColorSpace*, unsigned int) + 460 frame #9: 0x00000001859d7190 QuartzCore`CA::Render::create_image(CGImage*, CGColorSpace*, unsigned int) + 1872 frame #10: 0x00000001859d5eec QuartzCore`CA::Render::copy_image(CGImage*, CGColorSpace*, unsigned int, double) + 372 frame #11: 0x00000001859d6a2c QuartzCore`CA::Render::prepare_image(CGImage*, CGColorSpace*, unsigned int, double) + 12 frame #12: 0x00000001859a9aa0 QuartzCore`CA::Layer::prepare_commit(CA::Transaction*) + 292 frame #13: 0x00000001859a8ca0 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 264 frame #14: 0x00000001859a89dc QuartzCore`CA::Transaction::commit() + 512 frame #15: 0x00000001859a20cc QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 80 frame #16: 0x0000000183268588 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32 frame #17: 0x000000018326632c CoreFoundation`__CFRunLoopDoObservers + 372 frame #18: 0x000000018326675c CoreFoundation`__CFRunLoopRun + 928 frame #19: 0x0000000183195680 CoreFoundation`CFRunLoopRunSpecific + 384 frame #20: 0x00000001846a4088 GraphicsServices`GSEventRunModal + 180 frame #21: 0x000000018800cd90 UIKit`UIApplicationMain + 204 * frame #22: 0x00000001000dafb0 VOIP`actual_main(argc=1, argv=0x000000016fd37a60) + 120 at main.m:16 frame #23: 0x00000001000db018 VOIP`main(argc=1, argv=0x000000016fd37a60) + 56 at main.m:24 frame #24: 0x0000000182d368b8 libdyld.dylib`start + 4 thread #18: tid = 0x34f551, 0x0000000182e393f0 libsystem_kernel.dylib`_kernelrpc_mach_vm_deallocate_trap + 8 frame #0: 0x0000000182e393f0 libsystem_kernel.dylib`_kernelrpc_mach_vm_deallocate_trap + 8 frame #1: 0x0000000182e39638 libsystem_kernel.dylib`mach_vm_deallocate + 32 frame #2: 0x0000000182e83fb4 libsystem_malloc.dylib`deallocate_pages + 88 frame #3: 0x0000000100339bc8 VOIP`pj_pool_destroy_int + 64 at pool.c:254 [opt] frame #4: 0x0000000100339b88 VOIP`pj_pool_destroy_int(pool=0x000000014f6f6e00) + 24 at pool.c:292 [opt] frame #5: 0x000000010033a194 VOIP`cpool_release_pool(pf=0x0000000100622548, pool=0x000000014f6f6e00) + 112 at pool_caching.c:238 [opt] frame #6: 0x000000010033fb18 VOIP`ios_stream_destroy(strm=0x000000014f6f6ea8) + 504 at ios_dev.m:1278 [opt] frame #7: 0x0000000100376e10 VOIP`pjmedia_vid_port_destroy(vp=0x000000014fc74518) + 116 at vid_port.c:822 [opt] frame #8: 0x00000001003d9b84 VOIP`free_vid_win(wid=<unavailable>) + 204 at pjsua_vid.c:817 [opt] frame #9: 0x00000001003db434 VOIP`pjsua_vid_stop_stream [inlined] dec_vid_win + 440 at pjsua_vid.c:848 [opt] frame #10: 0x00000001003db3f8 VOIP`pjsua_vid_stop_stream(call_med=0x000000010062be40) + 380 at pjsua_vid.c:1177 [opt] frame #11: 0x00000001003d3710 VOIP`stop_media_stream(call=0x000000010062bce8, med_idx=1) + 92 at pjsua_media.c:2314 [opt] frame #12: 0x00000001003d24a4 VOIP`pjsua_media_channel_deinit [inlined] stop_media_session(call_id=<unavailable>) + 20 at pjsua_media.c:2361 [opt] frame #13: 0x00000001003d2490 VOIP`pjsua_media_channel_deinit(call_id=3) + 192 at pjsua_media.c:2385 [opt] frame #14: 0x00000001003c4c50 VOIP`pjsua_call_on_state_changed(inv=<unavailable>, e=<unavailable>) + 680 at pjsua_call.c:3704 [opt] frame #15: 0x000000010031b598 VOIP`inv_set_state(inv=0x0000000151edd168, state=<unavailable>, e=0x000000016e891fd8) + 240 at sip_inv.c:257 [opt] frame #16: 0x0000000100320974 VOIP`inv_respond_incoming_bye(inv=<unavailable>, bye_tsx=<unavailable>, rdata=<unavailable>, e=<unavailable>) + 156 at sip_inv.c:3300 [opt] frame #17: 0x000000010031d9f4 VOIP`mod_inv_on_tsx_state(tsx=0x000000014ede80a8, e=0x000000016e891fd8) + 84 at sip_inv.c:677 [opt] frame #18: 0x00000001003bf4f0 VOIP`pjsip_dlg_on_tsx_state(dlg=0x000000014f65b4a8, tsx=0x000000014ede80a8, e=0x000000016e891fd8) + 156 at sip_dialog.c:2013 [opt] frame #19: 0x00000001003b9c50 VOIP`tsx_set_state(tsx=0x000000014ede80a8, state=PJSIP_TSX_STATE_TRYING, event_src_type=<unavailable>, event_src=<unavailable>) + 292 at sip_transaction.c:1213 [opt] frame #20: 0x00000001003b93f8 VOIP`tsx_on_state_null(tsx=<unavailable>, event=<unavailable>) + 320 at sip_transaction.c:2411 [opt] frame #21: 0x00000001003b9fd4 VOIP`pjsip_tsx_recv_msg(tsx=0x000000014ede80a8, rdata=0x000000014e963f28) + 148 at sip_transaction.c:1775 [opt] frame #22: 0x00000001003bed40 VOIP`pjsip_dlg_on_rx_request(dlg=0x000000014f65b4a8, rdata=0x000000014e963f28) + 660 at sip_dialog.c:1660 [opt] frame #23: 0x00000001003c00d0 VOIP`mod_ua_on_rx_request(rdata=0x000000014e963f28) + 396 at sip_ua_layer.c:693 [opt] frame #24: 0x00000001003adc7c VOIP`pjsip_endpt_process_rx_data(endpt=0x000000014f0b4aa8, rdata=0x000000014e963f28, p=<unavailable>, p_handled=0x000000016e89231c) + 344 at sip_endpoint.c:886 [opt] frame #25: 0x00000001003ad6c4 VOIP`endpt_on_rx_msg(endpt=0x000000014f0b4aa8, status=<unavailable>, rdata=0x000000014e963f28) + 400 at sip_endpoint.c:1036 [opt] frame #26: 0x00000001003b2938 VOIP`pjsip_tpmgr_receive_packet(mgr=<unavailable>, rdata=<unavailable>) + 204 at sip_transport.c:1884 [opt] frame #27: 0x00000001003b537c VOIP`on_data_read(asock=<unavailable>, data=0x000000014e964068, size=741, status=<unavailable>, remainder=0x000000016e892600) + 176 at sip_transport_tcp.c:1425 [opt] frame #28: 0x0000000100335944 VOIP`ioqueue_on_read_complete(key=0x000000014f0b5560, op_key=0x000000014fce0080, bytes_read=<unavailable>) + 324 at activesock.c:493 [opt] frame #29: 0x0000000100330544 VOIP`ioqueue_dispatch_read_event(ioqueue=<unavailable>, h=0x000000014f0b5560) + 676 at ioqueue_common_abs.c:591 [opt] frame #30: 0x0000000100331cb0 VOIP`pj_ioqueue_poll(ioqueue=0x000000014e93f628, timeout=<unavailable>) + 796 at ioqueue_select.c:966 [opt] frame #31: 0x00000001003ada30 VOIP`pjsip_endpt_handle_events2(endpt=0x000000014f0b4aa8, max_timeout=<unavailable>, p_count=0x000000016e892edc) + 140 at sip_endpoint.c:741 [opt] frame #32: 0x00000001003cc1f8 VOIP`worker_thread [inlined] pjsua_handle_events(msec_timeout=10) + 32 at pjsua_core.c:1856 [opt] frame #33: 0x00000001003cc1d8 VOIP`worker_thread(arg=<unavailable>) + 36 at pjsua_core.c:696 [opt] frame #34: 0x0000000100332db8 VOIP`thread_main(param=0x000000014f209bf0) + 84 at os_core_unix.c:541 [opt] frame #35: 0x0000000182f1bb28 libsystem_pthread.dylib`_pthread_body + 156 frame #36: 0x0000000182f1ba8c libsystem_pthread.dylib`_pthread_start + 156 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20160317/d31b0b09/attachment.html>