I am trying to embed a youtube video in a UIWebView the code I have works fine however, every time I play the video and the video players opens I get a warning:
This application is modifying the autolayout engine from a background
thread, which can lead to engine corruption and weird crashes. This
will cause an exception in a future release.
Stack:( 0
CoreFoundation 0x0000000181e96dc8 +
148 1 libobjc.A.dylib 0x00000001814fbf80
objc_exception_throw + 56 2 CoreFoundation
0x0000000181e96cf8 + 0 3 Foundation
0x0000000182947b2c + 88 4 Foundation
0x00000001827c8c3c + 36 5 UIKit
0x00000001870fcd98 + 64 6 UIKit
0x00000001870fd8b0 + 244 7 UIKit
0x000000018788b7f0 + 268 8 UIKit
0x0000000187308aa0 + 176 9 UIKit
0x0000000186ff01e4 + 656 10 QuartzCore
0x0000000184982994 + 148 11 QuartzCore
0x000000018497d5d0 + 292 12 QuartzCore
0x000000018497d490 + 32 13 QuartzCore
0x000000018497cac0 + 252 14 QuartzCore
0x000000018497c820 + 500 15 WebCore
0x0000000186b56270 + 176 16 WebCore
0x0000000186b18fa4 + 368 17 CoreFoundation
0x0000000181e4d09c + 24 18 CoreFoundation
0x0000000181e4cb30 + 540 19 CoreFoundation
0x0000000181e4a830 + 724 20 CoreFoundation
0x0000000181d74c50 CFRunLoopRunSpecific + 384 21 WebCore
0x0000000185d6261c + 456 22 libsystem_pthread.dylib
0x0000000181afbb28 + 156 23 libsystem_pthread.dylib
0x0000000181afba8c + 0 24 libsystem_pthread.dylib
0x0000000181af9028 thread_start + 4 )
The Code I use is:
let string = "<html style='margin:0;background:black;'><body style='margin:0;background:black;'><iframe style='position:absolue;top:0;left:0;margin:0;' width='\(webViewWidth)' height='\(webViewHeight)' src='\(src)' frameborder='0' allowfullscreen></iframe></body></html>"
webViewYT.loadHTMLString(string as String, baseURL: nil)
Looking online I found out that I have to encapsulate UI changes in a dispatch_async.
How can I resolve this issue?
Related
I try to fix an error on firebase.
My sources are based on objective-c, and "webkit" is a problem in my code
I try and try to find what is cause of it, but I can't. Because these errors appears in a different places but same error.
stack trace : com.apple.main-thread
**EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000028**
keyboard_arrow_up
arrow_right 0
WebKit
WebKit::ProcessThrottler::setAssertionType(WebKit::ProcessAssertionType) + 544
I know it has only few clues for finding. Sorry.
My codes have a lot of request datas to Server and response from Server on mainthread.
I expect it occurs this problem but I'm not sure.
Thanks.
full call stack
Crashed: com.apple.main-thread
0 WebKit 0x199361fcc WebKit::ProcessThrottler::setAssertionType(WebKit::ProcessAssertionType) + 544
1 WebKit 0x199361fb4 WebKit::ProcessThrottler::setAssertionType(WebKit::ProcessAssertionType) + 520
2 WebKit 0x199362484 WebKit::ProcessThrottler::sendPrepareToSuspendIPC(WebKit::IsSuspensionImminent) + 596
3 WebKit 0x199367620 WTF::Detail::CallableWrapper<WebKit::ProcessThrottler::setAssertionType(WebKit::ProcessAssertionType)::$_1, void>::call() + 144
4 WebKit 0x199435e40 -[WKProcessAssertionBackgroundTaskManager _notifyAssertionsOfImminentSuspension] + 436
5 WebKit 0x1994364b0 -[WKProcessAssertionBackgroundTaskManager _handleBackgroundTaskExpirationOnMainThread] + 312
6 JavaScriptCore 0x197034278 WTF::Detail::CallableWrapper<WTF::callOnMainAndWait(WTF::Function<void ()>&&, WTF::MainStyle)::$_0, void>::call() + 48
7 JavaScriptCore 0x197049324 WTF::RunLoop::performWork() + 484
8 JavaScriptCore 0x197049f24 WTF::RunLoop::performWork(void*) + 36
9 CoreFoundation 0x18cfdb81c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
10 CoreFoundation 0x18cfdb718 __CFRunLoopDoSource0 + 208
11 CoreFoundation 0x18cfdaa28 __CFRunLoopDoSources0 + 268
12 CoreFoundation 0x18cfd4d20 __CFRunLoopRun + 824
13 CoreFoundation 0x18cfd44bc CFRunLoopRunSpecific + 600
14 GraphicsServices 0x1a3ae6820 GSEventRunModal + 164
15 UIKitCore 0x18f981164 -[UIApplication _run] + 1072
16 UIKitCore 0x18f986840 UIApplicationMain + 168
17 MyApp 0x10235f3d0 main + 29 (main.m:29)
18 libdyld.dylib 0x18cc9be40 start + 4
I have the following crash report but I can't figure out the cause of this crash. This crash appears quite frequently but the pattern varies at each time. Many thanks!
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000198337270 __pthread_kill + 8
1 libsystem_c.dylib 0x00000001982aeb18 abort + 112
2 libsystem_malloc.dylib 0x00000001983723e4 <redacted> + 0
3 libsystem_malloc.dylib 0x00000001983712f8 <redacted> + 192
4 CoreFoundation 0x00000001866c55e8 <redacted> + 192
5 CoreFoundation 0x00000001865d1394 CFRelease + 328
6 CoreFoundation 0x00000001866bc2bc _CFStringCreateWithFormatAndArgumentsAux2 + 272
7 Foundation 0x0000000187502448 -[NSPlaceholderString initWithFormat:locale:arguments:] + 172
8 0x000000010020f088 _mh_execute_header + 1536136
9 0x0000000100225614 _mh_execute_header + 1627668
10 0x00000001001ac6d0 _mh_execute_header + 1132240
11 CFNetwork 0x00000001861745b8 <redacted> + 80
12 CFNetwork 0x0000000186174548 <redacted> + 208
13 CFNetwork 0x00000001861746c4 <redacted> + 60
14 CFNetwork 0x0000000186047990 <redacted> + 104
15 CFNetwork 0x000000018611150c <redacted> + 104
16 CFNetwork 0x0000000186033ac8 <redacted> + 76
17 CoreFoundation 0x00000001865d4cdc CFArrayApplyFunction + 68
18 CFNetwork 0x0000000186033974 <redacted> + 136
19 CFNetwork 0x0000000186033828 <redacted> + 312
20 CFNetwork 0x0000000186033654 <redacted> + 68
21 CoreFoundation 0x00000001866ac240 <redacted> + 24
22 CoreFoundation 0x00000001866ab4e4 <redacted> + 264
23 CoreFoundation 0x00000001866a9594 <redacted> + 712
24 CoreFoundation 0x00000001865d52d4 CFRunLoopRunSpecific + 396
25 GraphicsServices 0x000000018fc9b6fc GSEventRunModal + 168
26 UIKit 0x000000018b19afac UIApplicationMain + 1488
27 0x000000010024bf1c _mh_execute_header + 1785628
28 libdyld.dylib 0x000000019821ea08 <redacted> + 4
I am assuming that you download some information from the web and are trying to create a string with some parts of that information:
6 CoreFoundation 0x00000001866bc2bc _CFStringCreateWithFormatAndArgumentsAux2 + 272
7 Foundation 0x0000000187502448 -[NSPlaceholderString initWithFormat:locale:arguments:] + 172
Where ever you are using information that you fetched from the Internet, you should first check if that information is valid and respects the right format you expect. Therefore, I recommend you to validate the information before using it.
this might help you:
iPhone app crash at [NSString stringWithFormat]
the error line must be:
[NSString stringWithFormat:#"%#,%#...",a,b...];
I'm getting a bizarre crash in a UIWebView where, somehow, MPVolumeView is somehow being instantiated by the OS, and not in the main thread. As a result, the application crashes.
Nowhere in my code is MPVolumeView being used or called, so I'm not sure what I should be doing here. The crash was not present in iOS 7 and only started to present itself in iOS 8.
Here's the traceback immediately before the crash:
Stacktrace: (
0 CustomFramework 0x000000010e918587 PSPDFAssertIfNotMainThread + 87
1 CustomFramework 0x000000010e918690 __PSPDFUIKitMainThreadGuard_block_invoke_2 + 32
2 UIKit 0x000000010cd2338c -[UIView initWithFrame:] + 153
3 MediaPlayer 0x0000000119b64b0d -[MPVolumeView initWithFrame:style:] + 80
4 UIKit 0x000000010cd22fb7 -[UIView init] + 62
5 WebCore 0x00000001151f9913 -[WebMediaSessionHelper initWithCallback:] + 115
6 WebCore 0x00000001151f9259 _ZN7WebCore22MediaSessionManageriOSC2Ev + 89
7 WebCore 0x00000001151f91d1 _ZN7WebCore19MediaSessionManager13sharedManagerEv + 49
8 WebCore 0x00000001151f7b6e _ZN7WebCore12MediaSessionC2ERNS_18MediaSessionClientE + 46
9 WebCore 0x0000000114be08a8 _ZN7WebCore16HTMLMediaSession6createERNS_18MediaSessionClientE + 40
10 WebCore 0x0000000114bc3545 _ZN7WebCore16HTMLMediaElementC2ERKNS_13QualifiedNameERNS_8DocumentEb + 1733
11 WebCore 0x0000000114c36118 _ZN7WebCore16HTMLVideoElementC2ERKNS_13QualifiedNameERNS_8DocumentEb + 24
12 WebCore 0x0000000114c34219 _ZN7WebCore16HTMLVideoElement6createERKNS_13QualifiedNameERNS_8DocumentEb + 57
13 WebCore 0x0000000114b9ef41 _ZN7WebCoreL16videoConstructorERKNS_13QualifiedNameERNS_8DocumentEPNS_15HTMLFormElementEb + 81
14 WebCore 0x0000000114b9df14 _ZN7WebCore18HTMLElementFactory13createElementERKNS_13QualifiedNameERNS_8DocumentEPNS_15HTMLFormElementEb + 356
15 WebCore 0x0000000114b8af85 _ZN7WebCore12HTMLDocument13createElementERKN3WTF12AtomicStringERi + 101
16 WebCore 0x0000000114e14f35 _ZN7WebCore40jsDocumentPrototypeFunctionCreateElementEPN3JSC9ExecStateE + 357
17 ??? 0x0000042139137034 0x0 + 4540738007092
18 JavaScriptCore 0x0000000117742d8e llint_entry + 22744
19 JavaScriptCore 0x000000011773d291 callToJavaScript + 311
20 JavaScriptCore 0x0000000117621be3 _ZN3JSC7JITCode7executeEPNS_2VMEPNS_14ProtoCallFrameE + 35
21 JavaScriptCore 0x0000000117603c93 _ZN3JSC11Interpreter7executeEPNS_17ProgramExecutableEPNS_9ExecStateEPNS_8JSObjectE + 8035
22 JavaScriptCore 0x000000011747272c _ZN3JSC8evaluateEPNS_9ExecStateERKNS_10SourceCodeENS_7JSValueEPS5_ + 508
23 WebCore 0x000000011546d2f4 _ZN7WebCore16ScriptController15evaluateInWorldERKNS_16ScriptSourceCodeERNS_15DOMWrapperWorldE + 260
24 WebCore 0x000000011546d609 _ZN7WebCore16ScriptController8evaluateERKNS_16ScriptSourceCodeE + 41
25 WebCore 0x0000000115473d62 _ZN7WebCore13ScriptElement13executeScriptERKNS_16ScriptSourceCodeE + 194
26 WebCore 0x0000000114bf6107 _ZN7WebCore16HTMLScriptRunner36executePendingScriptAndDispatchEventERNS_13PendingScriptE + 231
27 WebCore 0x0000000114bf68a7 _ZN7WebCore16HTMLScriptRunner29executeParsingBlockingScriptsEv + 135
28 WebCore 0x0000000114b8e3fb _ZN7WebCore18HTMLDocumentParser14notifyFinishedEPNS_14CachedResourceE + 59
29 WebCore 0x000000011477f067 _ZN7WebCore14CachedResource11checkNotifyEv + 343
30 WebCore 0x0000000115553347 _ZN7WebCore17SubresourceLoader16didFinishLoadingEd + 119
31 CFNetwork 0x0000000110e205f7 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
32 CFNetwork 0x0000000110eec871 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 273
33 CFNetwork 0x0000000110e0bb36 _ZN19RunloopBlockContext13_invoke_blockEPKvPv + 72
34 CoreFoundation 0x000000010eebe714 CFArrayApplyFunction + 68
35 CFNetwork 0x0000000110e0b9f7 _ZN19RunloopBlockContext7performEv + 133
36 CFNetwork 0x0000000110e0b836 _ZN17MultiplexerSource7performEv + 256
37 CFNetwork 0x0000000110e0b64c _ZN17MultiplexerSource8_performEPv + 72
38 CoreFoundation 0x000000010eeebad1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
39 CoreFoundation 0x000000010eee199d __CFRunLoopDoSources0 + 269
40 CoreFoundation 0x000000010eee0fd4 __CFRunLoopRun + 868
41 CoreFoundation 0x000000010eee0a06 CFRunLoopRunSpecific + 470
42 WebCore 0x00000001156e8a95 _ZL12RunWebThreadPv + 469
43 libsystem_pthread.dylib 0x000000010f842899 _pthread_body + 138
44 libsystem_pthread.dylib 0x000000010f84272a _pthread_struct_init + 0
45 libsystem_pthread.dylib 0x000000010f846fc9 thread_start + 13
You have a framework that "ensures" no UIKit methods are called on a background thread. However, as you see, this kinds of frameworks are not recommended in a production environment, only in a debug environment.
This is an Apple framework bug. It has been reported, and you should create a bug report as well.
Make sure to update your helper framework to the latest version:
https://gist.github.com/steipete/5664345
My recommendation would be to surround this framework with #if DEBUG statements. This should not be running on production code. Even the author of the framework says so:
You should only use this in debug builds. It doesn't use private
API, but I wouldn't ship it.
I have a question about monotouch app memory limitation.
I tried to stress my iPad memory with a very simple app that allocates 1MB arrays into a list. On each loop I display the number of loop. I notice my app crashing around 130 MB allocation.
My code:
List<byte[]> arrays = new List<byte[]>();
try
{
for (int i = 0; i < 1323; i++)
{
arrays.Add(new byte[1024 * 1024]);
Console.WriteLine("RAM: " + (i + 1) + " Mo");
}
}
catch { }
I don't understand why, on an iPad 3 or iPad 4, my app crashes around 130MB with following message:
Native stacktrace:
0 TestMemory 0x002687f9 mono_handle_native_sigsegv + 244
1 TestMemory 0x00295d75 sigabrt_signal_handler + 112
2 libsystem_c.dylib 0x35a75e93 _sigtramp + 42
3 libsystem_c.dylib 0x35a6c123 pthread_kill + 58
4 libsystem_c.dylib 0x35aa8973 abort + 94
5 TestMemory 0x0026353d GC_expand_hp_inner + 0
6 TestMemory 0x00263637 GC_expand_hp_inner + 250
7 TestMemory 0x00263aed GC_collect_or_expand + 128
8 TestMemory 0x00265d99 GC_alloc_large + 96
9 TestMemory 0x00265fe9 GC_generic_malloc + 180
10 TestMemory 0x00266185 GC_malloc_atomic + 112
11 TestMemory 0x0028c011 mono_array_new_specific + 124
12 TestMemory 0x00172e04 wrapper_managed_to_native_object___icall_wrapper_mono_array_new_specific_intptr_int + 68
13 TestMemory 0x0007305c MonoTouch_UIKit_UIControlEventProxy_Activated + 68
14 TestMemory 0x0016df50 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
15 TestMemory 0x002314e3 mono_jit_runtime_invoke + 1054
16 TestMemory 0x0028c8c3 mono_runtime_invoke + 90
17 TestMemory 0x0022b6f7 native_to_managed_trampoline_MonoTouch_UIKit_UIControlEventProxy_Activated + 178
18 UIKit 0x3ace40a5 <redacted> + 72
19 UIKit 0x3ace4057 <redacted> + 30
20 UIKit 0x3ace4035 <redacted> + 44
21 UIKit 0x3ace38eb <redacted> + 502
22 UIKit 0x3ace357b <redacted> + 242
23 UIKit 0x3ac0c523 <redacted> + 318
24 UIKit 0x3abf9801 <redacted> + 380
25 UIKit 0x3abf911b <redacted> + 6154
26 GraphicsServices 0x3637c5a3 <redacted> + 590
27 GraphicsServices 0x3637c1d3 <redacted> + 34
28 CoreFoundation 0x38856173 <redacted> + 34
29 CoreFoundation 0x38856117 <redacted> + 138
30 CoreFoundation 0x38854f99 <redacted> + 1384
31 CoreFoundation 0x387c7ebd CFRunLoopRunSpecific + 356
32 CoreFoundation 0x387c7d49 CFRunLoopRunInMode + 104
33 GraphicsServices 0x3637b2eb GSEventRunModal + 74
34 UIKit 0x3ac4d2f9 UIApplicationMain + 1120
35 TestMemory 0x0008b3c4 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
36 TestMemory 0x00219bf0 TestMemory_Application_Main_string__ + 152
37 TestMemory 0x0016df50 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
38 TestMemory 0x002314e3 mono_jit_runtime_invoke + 1054
39 TestMemory 0x0028c8c3 mono_runtime_invoke + 90
40 TestMemory 0x0028f3a7 mono_runtime_exec_main + 306
41 TestMemory 0x0029262b mono_runtime_run_main + 482
42 TestMemory 0x00242ecf mono_jit_exec + 94
43 TestMemory 0x002cce3c main + 2220
44 TestMemory 0x00002028 start + 40
You crash because you use up all the memory iOS is willing to give you. This is not a MonoTouch limitation, it's an iOS limitation.
I have been trying to figure out what is causing one of the top crashes in my iOS application. It looks like there is some layout happening on a background thread which is causing it to crash. Is there any way to determine what I might be doing that is triggering this relayout? I assume from the stack that it is related to a UIWebView when my app is being brought back into the foreground.
Other stackoverflow threads on the topic seem to mention things like triggering a table reload on a background thread. As far as I can see all the webView delegate methods get called on the main thread. Is there some case where this is not true or are there some other methods which get called on a background thread and I'm just not aware?
Web Thread - Crashed.
0 WebCore _WebTryThreadLock(bool) + 297
1 WebCore _WebTryThreadLock(bool) + 288
2 WebCore WebThreadLock + 66
3 UIKit -[UIWebDocumentView(UIWebDocumentViewTextSelecting) selectionBaseWritingDirection] + 10
4 UIKit -[UITextField _currentTextAlignment] + 86
5 UIKit -[UITextField _showsClearButtonWhenNonEmpty:] + 58
6 UIKit -[UITextField _textRectForBounds:forEditing:] + 678
7 UIKit -[UITextField editingRectForBounds:] + 52
8 UIKit -[UITextField editRect] + 70
9 UIKit -[UITextField layoutSubviews] + 1320
10 UIKit -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 258
11 QuartzCore -[CALayer layoutSublayers] + 214
12 QuartzCore CA::Layer::layout_if_needed(CA::Transaction*) + 460
13 QuartzCore CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
14 QuartzCore CA::Context::commit_transaction(CA::Transaction*) + 238
15 QuartzCore CA::Transaction::commit() + 316
16 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 60
17 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
18 CoreFoundation __CFRunLoopDoObservers + 276
19 CoreFoundation CFRunLoopRunSpecific + 394
20 CoreFoundation CFRunLoopRunInMode + 104
21 WebCore RunWebThread(void*) + 444
22 libsystem_c.dylib pthread_start + 308
Main - Thread
0 libsystem_kernel.dylib __psynch_mutexwait + 24
1 libsystem_c.dylib pthread_mutex_lock + 392
2 WebCore _WebTryThreadLock(bool) + 336
3 WebCore WebThreadLock + 66
4 WebKit -[WebDatabasePauser applicationWillEnterForeground] + 16
5 CoreFoundation _CFXNotificationPost + 1426
6 Foundation -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
7 UIKit -[UIApplication _sendWillEnterForegroundCallbacks] + 154
8 UIKit -[UIApplication _handleApplicationResumeEvent:] + 1094
9 UIKit -[UIApplication handleEvent:withNewEvent:] + 1292
10 UIKit -[UIApplication sendEvent:] + 72
11 UIKit _UIApplicationHandleEvent + 6154
12 GraphicsServices _PurpleEventCallback + 590
13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
14 CoreFoundation __CFRunLoopDoSources0 + 212
15 CoreFoundation __CFRunLoopRun + 646
16 CoreFoundation CFRunLoopRunSpecific + 356
17 CoreFoundation CFRunLoopRunInMode + 104
18 GraphicsServices GSEventRunModal + 74
19 UIKit UIApplicationMain + 1120
20 AppName main.m line 23
It seems you are updating UI on the background thread, in your code add this line wherever you are updating your UI and you are fetching data on the background thread:
dispatch_async(dispatch_get_main_queue(), ^{
// Update data here
});
As soon as you, rather code feels that data is there on device and it's time to update the UI corresponding to new data then try and bring back main thread in action.
Hope it helps.