iPad Cordova app sometimes crashes on launch - ios

My iPad app crashes on launch. It is reported only by some users.
Reinstalling the app seems to make it work.
Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread: 3
Application Specific Information:
<BKNewProcess: 0x14c5303c0; com.xxx.xxx; pid: 478; hostpid: -1> has active assertions beyond permitted time:
{(
<BKProcessAssertion: 0x14c6185c0> id: 478-1FE86162-9E03-459B-B266-BCEF0B247A17 name: Called by XXXX, from -[AppDelegate applicationDidEnterBackground:] process: <BKNewProcess: 0x14c5303c0; com.xxx.xxx; pid: 478; hostpid: -1> permittedBackgroundDuration: 180.000000 reason: finishTask owner pid:478 preventSuspend preventIdleSleep preventSuspendOnSleep
)}
Elapsed total CPU time (seconds): 380.760 (user 380.760, system 0.000), 98% CPU
Elapsed application CPU time (seconds): 0.061, 0% CPU
My background task code is
- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
NSLog(#"Background time remaining in didEnterBackground:%f",[[UIApplication sharedApplication] backgroundTimeRemaining]);
__block UIBackgroundTaskIdentifier backgroundTask;
backgroundTask = [application beginBackgroundTaskWithExpirationHandler: ^ {
[application endBackgroundTask: backgroundTask];
backgroundTask = UIBackgroundTaskInvalid;
NSLog(#"Background task Completed.");
}];
}
thread 3:
Thread 3 name: com.apple.NSURLConnectionLoader
Thread 3:
0 libsystem_kernel.dylib 0x389814f0 0x38980000 + 5360
1 libsystem_kernel.dylib 0x389812e5 0x38980000 + 4837
2 CoreFoundation 0x2a750317 0x2a684000 + 836375
3 CoreFoundation 0x2a74e8bd 0x2a684000 + 829629
4 CoreFoundation 0x2a69c3bd 0x2a684000 + 99261
5 CoreFoundation 0x2a69c1cf 0x2a684000 + 98767
6 CFNetwork 0x2a251953 0x2a1d5000 + 510291
7 Foundation 0x2b49ab57 0x2b3ca000 + 854871
8 libsystem_pthread.dylib 0x38a11e91 0x38a0f000 + 11921
9 libsystem_pthread.dylib 0x38a11e03 0x38a0f000 + 11779
10 libsystem_pthread.dylib 0x38a0fb8c 0x38a0f000 + 2956
Based on the Xcode documentation, i see that this exception type means that the watchdog is terminating the app. I'm not able to reproduce the crash and do not have the device console logs.
Please help to analyze this crash log.

Related

Crash on one specific Unity scene in iOS build - TexturesMetal::AddCreatedTexture

I am having a crash only on one specific scene in my AR Foundation Unity build with the following error.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000020
VM Region Info: 0x20 is not in any region. Bytes before following region: 4362387424
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
__TEXT 10404c000-104050000 [ 16K] r-x/r-x SM=COW ...lycoroTestApp
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [5380]
Triggered by Thread: 28
Thread 28 name:
Thread 28 Crashed:
0 libobjc.A.dylib 0x0000000195ac5ac0 objc_retain + 16 (objc-object.h:636)
1 UnityFramework 0x00000001066d5320 TexturesMetal::AddCreatedTexture(TextureID, id, bool) + 32 (TexturesMetal.mm:481)
2 UnityFramework 0x0000000106634828 GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) + 21972 (GfxDeviceWorker.cpp:0)
3 UnityFramework 0x00000001066aa2ec GfxDeviceWorkerAutoreleasePoolProxy + 68 (GfxDeviceMetal.mm:5242)
4 UnityFramework 0x0000000106636bd0 GfxDeviceWorker::RunExt(ThreadedStreamBuffer&) + 92 (GfxDeviceWorker.cpp:389)
5 UnityFramework 0x0000000106636b68 GfxDeviceWorker::Run() + 156 (GfxDeviceWorker.cpp:373)
6 UnityFramework 0x000000010662ef70 GfxDeviceWorker::RunGfxDeviceWorker(void*) + 12 (GfxDeviceWorker.cpp:352)
7 UnityFramework 0x00000001062289f8 Thread::RunThreadWrapper(void*) + 496 (Thread.cpp:81)
8 libsystem_pthread.dylib 0x00000001c9777c74 _pthread_start + 288 (pthread.c:887)
9 libsystem_pthread.dylib 0x00000001c977c878 thread_start + 8
At first I thought it was because I was missing the Environmental Probe manager in that scene (no). Then I thought perhaps it was because I was using a specific shader that didn't use a _MainTex. But I use that shader no problem in other working scenes.
And then I built the scene with only a simple primitive and my UI and still received this error. After that crash the scene did open successfully, but obviously the problem is still there. The UI is the exact same as the other working scenes.
I can't find out much about this specific error: TexturesMetal::AddCreatedTexture - only that there may be this bug with GLES3 and PVRTC textures - but they aren't present in the most recent build.
https://issuetracker.unity3d.com/issues/ios-crash-in-uploadtexture-at-texturesmeta-dot-mm-or-drawbufferranges-at-gfxdevicegles-dot-cpp-using-atlas-with-pvrtc-compress
The scene works perfectly in Android - it only crashes in iOS.
Any ideas? Full report below.
I ran a Product>Analysis in Xcode and it gave me this warning:
/Users/xcodeclub/Downloads/Eliot Silver/Classes/UI/UnityView.mm:200:5: nil returned from a method that is expected to return a non-null value
For this bit of Code in UnityView.mm:
static Class UnityRenderingView_LayerClassMTL(id self_, SEL _cmd)
{
return NSClassFromString(#"CAMetalLayer");
}
static Class UnityRenderingView_LayerClassNULL(id self_, SEL _cmd)
{
return NSClassFromString(#"CALayer");
}
#implementation UnityRenderingView
(Class)layerClass
{
return nil;
}
(void)InitializeForAPI:(UnityRenderingAPI)api
{
IMP layerClassImpl = api == apiMetal ? (IMP)UnityRenderingView_LayerClassMTL : (IMP)UnityRenderingView_LayerClassNULL;
class_replaceMethod(object_getClass([UnityRenderingView class]), #Selector(layerClass), layerClassImpl, UIView_LayerClass_Enc);
}
#End

App crashing when launching from AppStore or TestFlight but working fine elseways

My application update has been rejected. Into the rejection message, they wrote "Application crashes at launch". I then tried my application but couldn't make it crash. So I used TestFlight and noticed that when I was launched my app from TestFlight or AppStore, it was crashing at launch. But if I launch my app normally, it does work without any crashes. The thing is this bug occurred since iOS 10 update. Now my application on store also crashes when launched from AppStore while it was working fine 2 weeks go.
Apple sent me a crash log:
Incident Identifier: 001969F1-F275-4AC3-AFE1-E0426957B702
CrashReporter Key: 5ad9695e945a7d5eb5d61fd18d1c3989ccd155b4
Hardware Model: xxx
Process: MyApp [400]
Path: /private/var/containers/Bundle/Application/644423A4-EFE7-41B1-99D9-47B46338A6E2/MyApp.app/MyApp
Identifier: com.MyApp.com
Version: 20160527 (2.7.9)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.MyApp.com [451]
Date/Time: 2016-09-22 11:19:22.6893 -0700
Launch Time: 2016-09-22 11:19:22.4164 -0700
OS Version: iPhone OS 10.0.1 (14A403)
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010008a864
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MyApp 0x1000efd3c specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift:218)
1 MyApp 0x1000ed310 #objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift)
2 UIKit 0x19888c42c <redacted> + 400
3 UIKit 0x198a9cb70 <redacted> + 3524
4 UIKit 0x198aa28e0 <redacted> + 1656
5 UIKit 0x198ab7080 <redacted> + 48
6 UIKit 0x198a9f8c4 <redacted> + 168
7 FrontBoardServices 0x1945798bc <redacted> + 36
8 FrontBoardServices 0x194579728 <redacted> + 176
9 FrontBoardServices 0x194579ad0 <redacted> + 56
10 CoreFoundation 0x192986278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
11 CoreFoundation 0x192985bc0 __CFRunLoopDoSources0 + 524
12 CoreFoundation 0x1929837c0 __CFRunLoopRun + 804
13 CoreFoundation 0x1928b2048 CFRunLoopRunSpecific + 444
14 UIKit 0x1988855dc <redacted> + 608
15 UIKit 0x198880360 UIApplicationMain + 208
16 MyApp 0x1000ee818 main (AppDelegate.swift:58)
17 libdispatch.dylib 0x1918945b8 (Missing)
There is 4 others threads but this one is the one crashing so I did not copy the rest. I did some research and even though I did notice my crash log wasn't fully translated (for some strange reason since I have all dsyms but whatever), I did manage to understand that I was crashing on line 217 (tell me if I'm wrong). I know that SIGTRAP are most of time NSExceptions being thrown. The line itself is:
let api = MyAppAPI.instance
The instance is a singleton. My guess is that something into the instance creation is failing. Here is the code:
static var instance: MyAppAPI = {
return Singleton.instance
}()
class MyAppAPI: Manager {
struct Singleton {
static var configuration: NSURLSessionConfiguration = {
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?? ""
configuration.HTTPAdditionalHeaders = [
"Accept": "application/vnd.MyApp.api+json, application/json;q=0.9",
"User-Agent": "MyApp iOS/\(version)",
"X-API-Version": "1.0.1"
]
return configuration
}()
static var instance = MyAppAPI(configuration: configuration)
static var baseURL : NSURL! = nil
}
I'm so desperate about this error, I did try a few things that did not work out. Am I looking into the right place ? Is there anyone with a solution ? Any kind of help would be greatly appreciated. I'm willing to gift anyone that can find me the solution or help me find the solution !
I found the solution of my problem.
As expected it was coming from func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
Inside the function I had let userInfo = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary.
I changed it to let userInfo = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary and then checked if userInfo != nil to make all the code running userInfointo the bracket.
If it helps anyone or if anyone is struggling with this issue, check all yours ! and swap these to ? if needed (on didFinishLaunchingWithOptions) since launching from TestFlight/AppStore seems to have different options than from installed application (just a guess, not pro enough to claim it).

Threading crash in Google Analytics for iOS

Using the Google Analytics library for iOS version 3.0.9, (and 3.0.x in general), we see a lot of crashes like the one below.
They appeared to occur randomly.
Exception Type: SIGBUS
Exception Codes: BUS_ADRALN at 0xe756c0
Crashed Thread: 19
Thread 19 Crashed:
0 libsystem_platform.dylib 0x39e02e18 0x39e01000 + 7704
1 CoreFoundation 0x2bfd0d6f 0x2bf92000 + 257391
2 CoreFoundation 0x2c0716a3 0x2bf92000 + 915107
3 CoreFoundation 0x2c070417 0x2bf92000 + 910359
4 CoreFoundation 0x2bfd4a0b 0x2bf92000 + 272907
5 Communicator 0x00714541 +[GAIUsageTracker trackTarget:action:] + 193
6 Communicator 0x007049b3 -[GAITrackerImpl send:] + 47
7 Communicator 0x00157b8d __66+[xxx]_block_invoke (xxx.m:305)
8 libdispatch.dylib 0x39ca58cb 0x39ca4000 + 6347
9 libdispatch.dylib 0x39caeda3 0x39ca4000 + 44451
10 libdispatch.dylib 0x39cafcd7 0x39ca4000 + 48343
11 libsystem_pthread.dylib 0x39e06e31 0x39e06000 + 3633
It turns out that the GAI library is not as thread-safe as it claims. We were able to fix our Google Analytics crashes by serializing the calls.
(void (^)(void))block = {
// your analytics call, eg
[[[GAI sharedInstance] defaultTracker] send:....];
};
static dispatch_queue_t theQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
theQueue = dispatch_queue_create("Analytics Queue", DISPATCH_QUEUE_SERIAL);
});
dispatch_async(theQueue, block);
So all calls to the tracker are executed in code blocks serialized on the same queue ("theQueue" above), which forces only one code block to execute at a time.

iOS screen become black little by little

I'm implementing an iOS app. and found that sometimes the screen became black little by little.
for example, in a view controller, there are a collection view, a button, a page controller, and sometimes I found the collection view became black(or invisible), only black background is shown, after 1-2 seconds, the button is gone, then the whole screen is black. but if I put the app into background, then bring it back, everything is ok.
here is the code:
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSTimeInterval timeLeft = [UIApplication sharedApplication].backgroundTimeRemaining - 1.0;
if(timeLeft &lt 0)
{
completionHandler(UIBackgroundFetchResultNoData);
}
//create new thread to do something, and sleep at current thread
...create new threads
[NSThread sleep:timeLeft];
completionHandler(UIBackgroundFetchResultNewData);
});
}
the issue could be reproduced if I repeat the following actions several times:
Do some thing
Put app to background(press home button)
Bring app back to foreground
repeat 1 - 3
we found following error in organizer for our app:
: CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.
after added , I got the following log:
Myapp[11496] : CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
0 QuartzCore 0x31ca6a75 + 268
1 QuartzCore 0x31ca6929 + 224
2 QuartzCore 0x31cabddb + 86
3 QuartzCore 0x31cab9f7 + 150
4 UIKit 0x3203f919 + 344
5 UIKit 0x320bb11b + 138
6 UIKit 0x322b0ebf + 218
7 UIKit 0x322b1169 + 104
8 UIKit 0x322b1735 + 36
9 Myapp 0x002e538d __61-[AppDelegate application:performFetchWithCompletionHandler:]_block_invoke + 632
10 libdispatch.dylib 0x3a487d53 + 10
11 libdispatch.dylib 0x3a48d689 + 228
12 libdispatch.dylib 0x3a48d8dd + 56
13 libsystem_pthread.dylib 0x3a5b8c17 _pthread_wqthread + 298
14 libsystem_pthread.dylib 0x3a5b8adc start_wqthread + 8
my questions is:
how could application:performFetchWithCompletionHandler cause animation issue?
to answer questions:
1. I'm sure that phone is not going to sleep
2. source code. sorry the project is too big
Check that you are working with UI on main thread only, this should be the case.
Edit: - I've seen this one, although never used it(written by Peter Steinberger).
Also this answer can help avoiding several more problems.
The thread created to perform your fetch invokes a call to update your ui, when it finishes performing whatever task it is doing, and its no longer needed it is deallocated. UIUpdates MUST be performed on the main thread or they might not be performed right away.
Have you tried dispatching to the main thread whatever ui update you are performing there?
It's hard to know what you your completion handler is doing, but if it's updating UI try to dispatch them on the main thread
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSTimeInterval timeLeft = [UIApplication sharedApplication].backgroundTimeRemaining - 1.0;
if(timeLeft < 0)
{
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(UIBackgroundFetchResultNoData);
});
}
//create new thread to do something, and sleep at current thread
...create new threads
[NSThread sleep:timeLeft];
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(UIBackgroundFetchResultNewData);
});
});
}

Proper way of preventing GPU access with Core Image when app is in background

I'm experiencing crashes from customers, with the following backtrace:
0 libGPUSupportMercury.dylib 0x3542ae2e gpus_ReturnNotPermittedKillClient + 10
1 IMGSGX543RC2GLDriver 0x30bbf5e5 SubmitPacketsIfAny + 245
2 GLEngine 0x32f827db glFinish_Exec + 167
3 CoreImage 0x31fb85b7 CI::GLESContext::recursive_render(CI::Node const*, CGRect, bool) + 219
4 CoreImage 0x31fbb351 CI::GLESContext::render(CI::Node*, CGRect) + 41
5 CoreImage 0x31fc2901 CI::image_get_cgimage(CI::Context*, CI::Image*, CGRect, CGColorSpace*, CI::PixelFormat) + 1313
6 CoreImage 0x31fa8427 -[CIContext createCGImage:fromRect:format:colorSpace:] + 487
7 CoreImage 0x31fa81e9 -[CIContext createCGImage:fromRect:] + 89
8 App 0x0013c9db -[PZTiledImageLayer drawInContext:] (PZTiledImageLayer.m:129)
Which are due to accessing the GPU when the app is in background (not allowed).
The code leading to this crash is this:
if([UIApplication sharedApplication].applicationState == UIApplicationStateActive)
{
cg_image = [self.imageContext createCGImage:im fromRect:rclip];
}
This means the app changes state after my check, but before GPU is accessing within the Core Image API.
What is the proper way of handling the situation of app background state when using this Core Image API?
If this is happening on a background thread, you could try moving it to the main thread. That way the execution of this function is not interleaved with the AppDelegate callback
- (void)applicationDidEnterBackground:(UIApplication *)application
and you can implement some signalling there without worrying about concurrency.

Resources