invalid context 0x0, Creating UIImage from CALayer - ios

I am trying to convert a CALayer to an UIImage with code from this post. Copied here. But when I use it I got tons of error. At first I put it in a NSObject class where I use to store a model. But then I read in the post I am suppose to put it in a controller, view or category of CALayer. I tried putting it in a controller or CALayer and it still doesn't work.
- (UIImage *)imageFromLayer:(CALayer *)layer
{
if ([[UIScreen mainScreen] respondsToSelector:#selector(scale)])
UIGraphicsBeginImageContextWithOptions([layer frame].size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext([layer frame].size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
ERROR:
<Error>: CGContextSetStrokeColorWithColor: invalid context 0x0
<Error>: CGContextSetLineWidth: invalid context 0x0
<Error>: CGContextMoveToPoint: invalid context 0x0
<Error>: CGContextAddArc: invalid context 0x0
<Error>: CGContextAddArc: invalid context 0x0
<Error>: CGContextAddArc: invalid context 0x0
<Error>: CGContextAddArc: invalid context 0x0
<Error>: CGContextClosePath: invalid context 0x0
<Error>: CGContextDrawPath: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextSetBaseCTM: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextEndTransparencyLayer: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0

Check if your layer parameter is nil. Usually a context cannot be created if the size has either width = 0 or height = 0 (or both).

Related

Watchkit`s WKInterfaceImage setImage causes "Terminated due to Memory error"

I want to animate images on a watch (like the activity app, if you´re interested, but it´s not important for this problem)
I draw images in a loop first: GlanceController.m
NSMutableArray *images = [[NSMutableArray alloc] init];
for(int i = 0, j = 0; i < 10; i++, j++){
#autoreleasepool {
// ...
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
// ...
// create UIImage and save it to an array for later
UIImage *ejCircle = UIGraphicsGetImageFromCurrentImageContext();
[images addObject: ejCircle];
ejCircle = nil;
UIGraphicsEndImageContext();
}
}
So far everything works fine, thanks to autoreleasepool, the memory consumption is not too high here, (about 5 mB before autoreleasepool gets drained back to 2 mB)
However now I try to animate this in a WKInterfaceImage, I get a Memory Error:
// take the array and create an animated image out of it
UIImage * img = [UIImage animatedImageWithImages:images duration:1.0];
// memory about normal 2 mB after this line
[wkInterfaceImage setImage:img]; // APP CRASHES HERE
// memory consumption jumps to 30 mB after this line: too much
// for the watch app, the app gets terminated.
[wkInterfaceImage startAnimatingWithImagesInRange:NSMakeRange(0,50) duration: 1.0 repeatCount: 1];
My question is, why the app crashes in this line. The memory consumption explodes, but I don´t alloc/malloc/new something here.
Edit
I just found this crash log in XCode Devices:
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Identifier: MyApp WatchKit Extension
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Version: ???
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Code Type: ARM-64 (Native)
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Parent Process: debugserver [620]
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Date/Time: 2015-07-14 16:04:04.134 +0200
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Launch Time: 2015-07-14 16:03:42.401 +0200
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: OS Version: iOS 8.4 (12H143)
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Report Version: 105
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Exception Type: EXC_RESOURCE
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Exception Subtype: MEMORY
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Exception Message: (Limit 30 MB) Crossed High Water Mark
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Triggered by Thread: 0
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Thread 0 name: Dispatch queue: com.apple.main-thread
Jul 14 16:04:04 iPhone-6-Plus ReportCrash[622] <Error>: Thread 0 Attributed:

iOS application crash while show popover

In application rootviewController allocated like
navigationContr = [[UINavigationController alloc] initWithRootViewController:loginViewController];
loginViewController = nil;
self.window.rootViewController = _navigationViewController;
After login I push MainViewController like this
MainViewController * mainViewController = [[MainViewController alloc]initWithNibName:#"MainViewController" bundle:nil];
mainViewController.isNavigateFromLogin = YES;
/** push the Main screen*/
[self.navigationController pushViewController:mainViewController animated:NO];
mainViewController = nil;
On MainViewController I am adding view of another viewController like this
gridViewControllerObj = [[GridViewController alloc]initWithNibName:#"GridViewController" bundle:nil];
[self.view addSubview:gridViewControllerObj.view];
GridViewController added on button, on button click we showed popover. Code below
Memory allocated to "operationsViewController"
self.optionsPopOver = [[UIPopoverController alloc]initWithContentViewController:operationsViewController];
[_orderOptionsPopOver presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
This is flow of show popover,if run app on device I see warning print on console. After time out I go back to first view
Issue 1:
BusinessApplication[8321] : Presenting view controllers on detached view controllers is discouraged .
For this case app work but not crash
To fix this warning ,I searched on forum for above warning, there are solution suggested like
AppDelegate *appDelegate = (AppDelegate* )[[UIApplication sharedApplication] delegate];
UIView *rootView = appDelegate.window.rootViewController.view;
After providing rootview to popover above warning goes of
[_orderOptionsPopOver presentPopoverFromRect:frame inView:rootView permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:NO];
Issue 2:
After apply of above solution on time out application get crashed.
I got following crash log
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
mstreamd[513] <Notice>: (Note ) PS: MSSubscriber - 1456278278 Finished retrieving assets. Checking for errors on 0 assets...
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Warning: sync SCNetworkReachability (by-name) query on main thread
BusinessApplication[511] <Warning>: Stack Trace: uncaughtExceptionHandler
(
0 CoreFoundation 0x25f0fd7f <redacted> + 150
1 libobjc.A.dylib 0x33aefc77 objc_exception_throw + 38
2 UIKit 0x29696533 <redacted> + 2918
3 UIKit 0x2969809b <redacted> + 94
4 UIKit 0x293c11a1 <redacted> + 72
5 UIKit 0x29697fcf <redacted> + 198
6 UIKit 0x2949c199 <redacted> + 168
7 UIKit 0x294c5741 <redacted> + 116
8 UIKit 0x294c4721 <redacted> + 120
9 UIKit 0x294037a3 <redacted> + 66
10 Foundation 0x26c16dc9 __NSFireDelayedPerform + 468
11 CoreFoundation 0x25ed6517 <redacted> + 14
12 CoreFoundation 0x25ed6099 <redacted> + 656
13 CoreFoundation 0x25ed4303 <redacted> + 1418
14 CoreFoundation 0x25e21981 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x25e21793 CFRunLoopRunInMode + 106
16 GraphicsServices 0x2d1b1051 GSEventRunModal + 136
17 UIKit 0x29413981 UIApplicationMain + 1440
18 BusinessApplication 0x003ddc17 main + 170
19 libdyld.dylib 0x3408baaf <redacted> + 2
)
BusinessApplication[511] <Warning>: CRASH: Application tried to present modally an active controller <MainViewController: 0x16a78b30>.
BusinessApplication[511] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <MainViewController: 0x16a78b30>.'
*** First throw call stack:
(0x25f0fd67 0x33aefc77 0x29696533 0x2969809b 0x293c11a1 0x29697fcf 0x2949c199 0x294c5741 0x294c4721 0x294037a3 0x26c16dc9 0x25ed6517 0x25ed6099 0x25ed4303 0x25e21981 0x25e21793 0x2d1b1051 0x29413981 0x3ddc17 0x3408baaf)
ReportCrash[516] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
ReportCrash[516] <Notice>: ReportCrash acting against PID 511
ReportCrash[516] <Notice>: Formulating crash report for process BusinessApplication[511]
mediaserverd[36] <Notice>: '' com.xp.businessApp(pid = 511) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
com.apple.xpc.launchd[1] (UIKitApplication:com.xp.businessApp[0x2b0f][511]) <Notice>: Service exited due to signal: Abort trap: 6
<Warning>: Application 'UIKitApplication:com.xp.businessApp[0x2b0f]' crashed.
assertiond[54] <Warning>: pid_suspend failed for <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511>: Unknown error: -1, Unknown error: -1
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 2, priority: No such process
assertiond[54] <Warning>: Could not set priority of <BKNewProcess: 0x16d885d0; com.xp.businessApp; pid: 511> to 4096, priority: No such process
UserEventAgent[17] <Warning>: id=com.xp.businessApp pid=511, state=0
ReportCrash[516] <Notice>: Saved report to /var/mobile/Library/Logs/CrashReporter/BusinessApplication_2015-03-14-171423_IPad.ips
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
mstreamd[513] <Notice>: (Note ) mstreamd: Not monitoring for external power.
mstreamd[513] <Notice>: (Note ) PS: Media stream daemon stopping.
mstreamd[513] <Notice>: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x14e30790>: Shared Streams daemon has shut down.
mstreamd[513] <Notice>: (Warn ) mstreamd: mstreamd shutting down.
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
<Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
locationd[60] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
The problem in what you're doing is that you've created a pitfall chain for yourself.
You create a couple of controllers, and present them, but after you present them, you deallocate them. You can't present something you deallocate. This leads to the first issue, trying to present another controller when your current controller is nil.
Next, you take the error message and search for a solution out of context. That is not a solution to your problem and obviously it will lead to a crash if you try and use it.
The first thing you need to do is to remove the nil assign. I don't know why you're doing it and I'm certain its causing many problems.
When you have *a = *b, and *c = *a, if you set c = nil, all of the rest of the variables will be nil as well because its how pointers work. I'm happy to help you some more if you don't mind somebody looking at your code, but I can't do much if problematic calls are still in there.

How to debug an iOS app crash at launch time, breakpoint only in assembly file

I'am facing an issue with an app currently in development.
The problem is that the App crash at launch time when it was in background for a while, and only in that case.
Launching the app while it was killed doesn't lead to crash, from debugger or from phone.
Launching the app while it was in background for about 5-10 min doesn't lead to crash, while debugging or not.
Launching the app while in backgorund for about 15-20 min lead to a crash. Using debugger and breakpoint on exception gave me this file :
libdispatch.dylib`_dispatch_assert_queue_fail:
0x349c6ce4: push {r4, r5, r7, lr}
0x349c6ce6: add r7, sp, #0x8
0x349c6ce8: sub sp, #0xc
0x349c6cea: movw r5, #0x7810
0x349c6cee: mov r4, r0
0x349c6cf0: movt r5, #0x1
0x349c6cf4: movw r12, #0x7af0
0x349c6cf8: movt r12, #0x1
0x349c6cfc: movw r9, #0x7a83
0x349c6d00: movt r9, #0x1
0x349c6d04: ldr r0, [r4, #0x48]
0x349c6d06: movw r2, #0x7a93
0x349c6d0a: movt r2, #0x1
0x349c6d0e: movw r3, #0x7af5
0x349c6d12: movt r3, #0x1
0x349c6d16: add r5, pc
0x349c6d18: cmp r0, #0x0
0x349c6d1a: it ne
0x349c6d1c: movne r5, r0
0x349c6d1e: add r12, pc
0x349c6d20: add r9, pc
0x349c6d22: add r3, pc
0x349c6d24: cmp r1, #0x0
0x349c6d26: add r2, pc
0x349c6d28: strd r4, r5, [sp]
0x349c6d2c: it ne
0x349c6d2e: movne r3, r12
0x349c6d30: add r0, sp, #0x8
0x349c6d32: mov r1, r9
0x349c6d34: blx 0x349dda4c ; symbol stub for: -[OS_object retainWeakReference]
0x349c6d38: movw r0, #0x7ae0
0x349c6d3c: movt r0, #0x1
0x349c6d40: ldr r1, [sp, #0x8]
0x349c6d42: add r0, pc
0x349c6d44: bl 0x349c65cc ; _dispatch_log
0x349c6d48: trap
0x349c6d4a: nop
The debugger break on the trap line, just before the nop at the end with :
Thread 1: EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xdefe)
I can't find any clue on how to debug this.
Any help would be appreciated.
EDIT : here is a crash log with the stacktrace (I replaced my device name with DeviceName and the app name and my company name with com.company.myAppName) :
Sep 22 11:36:31 DeviceName locationd[63] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
Sep 22 11:36:31 DeviceName myAppName[6750] <Warning>: *** Assertion failure in -[UIFetchContentInBackgroundAction sendResponse:], /SourceCache/BaseBoard/BaseBoard-97/BaseBoard/BSAction.m:221
Sep 22 11:36:32 DeviceName myAppName[6750] <Notice>: BUG in client of libdispatch: Assertion failed: Block was run on an unexpected queue
Expected queue: 0x0x3713cd40[com.apple.main-thread]
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Notice>: ReportCrash acting against PID 6750
Sep 22 11:36:32 DeviceName diagnosticd[5999] <Error>: error evaluating process info - pid: 6750, punique: 6750
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Notice>: Formulating crash report for process myAppName[6750]
Sep 22 11:36:32 DeviceName SpringBoard[2836] <Warning>: BSXPCMessage received error for message: Connection invalid
Sep 22 11:36:32 DeviceName wifid[68] <Notice>: WiFi:[433071392.290519]: BG Application: Not Present, BG Daemon: Present. Daemons: lockdownd networkd assistantd
Sep 22 11:36:32 DeviceName com.apple.xpc.launchd[1] (UIKitApplication:com.company.myAppName[0x3ff0][6750]) <Notice>: Service exited due to signal: Trace/BPT trap: 5
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Not saving crash log because we have reached the limit for logs to store on disk. Sync or otherwise clear logs from /var/mobile/Library/Logs/CrashReporter to save new logs.
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Could not save crash report to disk!
Sep 22 11:36:32 DeviceName SpringBoard[2836] <Warning>: Application 'UIKitApplication:com.company.myAppName[0x3ff0]' crashed.
Sep 22 11:36:32 DeviceName assertiond[57] <Warning>: Could not set priority of <BKNewProcess: 0x145437b0; com.company.myAppName; pid: 6750> to 2, priority: No such process
Sep 22 11:36:32 DeviceName assertiond[57] <Warning>: Could not set priority of <BKNewProcess: 0x145437b0; com.company.myAppName; pid: 6750> to 4096, priority: No such process
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Incident Identifier: DF8D30C9-4F46-43CB-B192-323E819180A6
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: CrashReporter Key: a93a18a1167cbedc4b3623154bd083fdd7770808
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Hardware Model: iPhone5,2
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Process: myAppName [6750]
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Path: /private/var/mobile/Containers/Bundle/Application/DE60F941-317E-49C2-95EA-0F152A117C16/myAppName.app/myAppName
Sep 22 11:36:32 DeviceName UserEventAgent[17] <Warning>: id=com.company.myAppName pid=6750, state=0
Sep 22 11:36:32 DeviceName backboardd[56] <Warning>: Unable to bootstrap_look_up port with name com.company.myAppName.gsEvents: unknown error code (1102)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Identifier: myAppName
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Version: ???
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Code Type: ARM (Native)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Parent Process: launchd [1]
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Date/Time: 2014-09-22 11:36:32.054 +0200
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Launch Time: 2014-09-22 11:25:29.726 +0200
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: OS Version: iOS 8.0 (12A365)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Report Version: 105
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Exception Type: EXC_BREAKPOINT (SIGTRAP)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Exception Codes: 0x0000000000000001, 0x000000000000defe
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Triggered by Thread: 0
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Last Exception Backtrace:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: (0x26db3e3a 0x34461c86 0x26db3d10 0x27a845aa 0x2b8bf8c8 0x349c8b64 0x2b8bf832 0x2a7c7ba8 0x349c18c6 0x349c18b2 0x349c50ba 0x26d79be4 0x26d782e4 0x26cc661c 0x26cc642e 0x2e0740a4 0x2a2b0804 0xcee48 0x349e1aaa)
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 0 Crashed:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libdispatch.dylib 0x349c6d48 0x349c0000 + 27976
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libdispatch.dylib 0x349c4be4 0x349c0000 + 19428
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 FrontBoardServices 0x2d4e7830 0x2d4df000 + 34864
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 FrontBoardServices 0x2d4f40e6 0x2d4df000 + 86246
Sep 22 11:36:32 DeviceName SpringBoard[2836] <Warning>: Unable to deliver -[UIRemoteApplication showTopMostMiniAlertWithSynchronizationPort:] message to port 0: (ipc/send) invalid destination port
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 CoreFoundation 0x26d7a5b2 0x26cae000 + 837042
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 5 CoreFoundation 0x26d79874 0x26cae000 + 833652
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 6 CoreFoundation 0x26d77ff6 0x26cae000 + 827382
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 7 CoreFoundation 0x26cc661c 0x26cae000 + 99868
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 8 CoreFoundation 0x26cc642e 0x26cae000 + 99374
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 9 myAppName 0x00177f72 0x4f000 + 1216370
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 10 CoreFoundation 0x26db416c 0x26cae000 + 1073516
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 11 libobjc.A.dylib 0x34461f10 0x3445b000 + 28432
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 12 libc++abi.dylib 0x33d9ade0 0x33d83000 + 97760
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 13 libc++abi.dylib 0x33d9a5a4 0x33d83000 + 95652
Sep 22 11:36:32 DeviceName locationd[63] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 14 libobjc.A.dylib 0x34461d5a 0x3445b000 + 27994
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 15 CoreFoundation 0x26db3d10 0x26cae000 + 1072400
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 16 Foundation 0x27a845aa 0x279f2000 + 599466
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 17 BaseBoard 0x2b8bf8c8 0x2b89b000 + 149704
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 18 libdispatch.dylib 0x349c8b64 0x349c0000 + 35684
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 19 BaseBoard 0x2b8bf832 0x2b89b000 + 149554
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 20 UIKit 0x2a7c7ba8 0x2a242000 + 5790632
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 21 libdispatch.dylib 0x349c18c8 0x349c0000 + 6344
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 22 libdispatch.dylib 0x349c18b4 0x349c0000 + 6324
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 23 libdispatch.dylib 0x349c50ba 0x349c0000 + 20666
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 24 CoreFoundation 0x26d79be4 0x26cae000 + 834532
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 25 CoreFoundation 0x26d782e4 0x26cae000 + 828132
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 26 CoreFoundation 0x26cc661c 0x26cae000 + 99868
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 27 CoreFoundation 0x26cc642e 0x26cae000 + 99374
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 28 GraphicsServices 0x2e0740a4 0x2e06b000 + 37028
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 29 UIKit 0x2a2b0804 0x2a242000 + 452612
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 30 myAppName 0x000cee48 0x4f000 + 523848
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 31 libdyld.dylib 0x349e1aac 0x349e0000 + 6828
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 1:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34a942a0 0x34a93000 + 4768
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libdispatch.dylib 0x349cd9fc 0x349c0000 + 55804
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libdispatch.dylib 0x349c331e 0x349c0000 + 13086
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 2 name: GAIThread Dispatch queue: NSPersistentStoreCoordinator 0x15582b60
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 2:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa9388 0x34a93000 + 91016
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsqlite3.dylib 0x347e4164 0x3474b000 + 627044
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsqlite3.dylib 0x3479334a 0x3474b000 + 295754
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 libsqlite3.dylib 0x347d2544 0x3474b000 + 554308
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 libsqlite3.dylib 0x347d1e54 0x3474b000 + 552532
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 5 libsqlite3.dylib 0x34792f8e 0x3474b000 + 294798
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 6 libsqlite3.dylib 0x34787c72 0x3474b000 + 248946
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 7 libsqlite3.dylib 0x347657dc 0x3474b000 + 108508
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 8 libsqlite3.dylib 0x34783f10 0x3474b000 + 233232
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 9 libsqlite3.dylib 0x34778ed6 0x3474b000 + 188118
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 10 CoreData 0x26ab7ab8 0x26aa2000 + 88760
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 11 CoreData 0x26af0d92 0x26aa2000 + 322962
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 12 CoreData 0x26b87110 0x26aa2000 + 938256
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 13 CoreData 0x26b6c3ac 0x26aa2000 + 828332
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 14 CoreData 0x26b717c8 0x26aa2000 + 849864
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 15 libdispatch.dylib 0x349c18b4 0x349c0000 + 6324
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 16 libdispatch.dylib 0x349c8b64 0x349c0000 + 35684
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 17 CoreData 0x26b65302 0x26aa2000 + 799490
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 18 CoreData 0x26b6bf9a 0x26aa2000 + 827290
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 19 CoreData 0x26b3d5be 0x26aa2000 + 636350
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 20 myAppName 0x0017312c 0x4f000 + 1196332
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 21 myAppName 0x00171c46 0x4f000 + 1190982
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 22 myAppName 0x00172fe2 0x4f000 + 1196002
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 23 myAppName 0x0017d77e 0x4f000 + 1238910
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 24 myAppName 0x0017e9ee 0x4f000 + 1243630
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 25 myAppName 0x0017e7ec 0x4f000 + 1243116
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 26 Foundation 0x27ac359a 0x279f2000 + 857498
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 27 CoreFoundation 0x26d7a58c 0x26cae000 + 837004
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 28 CoreFoundation 0x26d7999a 0x26cae000 + 833946
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 29 CoreFoundation 0x26d78000 0x26cae000 + 827392
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 30 CoreFoundation 0x26cc661c 0x26cae000 + 99868
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 31 CoreFoundation 0x26cc642e 0x26cae000 + 99374
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 32 Foundation 0x279fe428 0x279f2000 + 50216
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 33 Foundation 0x27a4c8e8 0x279f2000 + 370920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 34 myAppName 0x0016f678 0x4f000 + 1181304
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 35 Foundation 0x27ac3386 0x279f2000 + 856966
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 36 libsystem_pthread.dylib 0x34b24e90 0x34b22000 + 11920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 37 libsystem_pthread.dylib 0x34b24e02 0x34b22000 + 11778
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 38 libsystem_pthread.dylib 0x34b22b8c 0x34b22000 + 2956
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 3:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa7b38 0x34a93000 + 84792
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b243f4 0x34b22000 + 9204
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b252d8 0x34b22000 + 13016
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 Foundation 0x27a48f62 0x279f2000 + 356194
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 myAppName 0x0011f036 0x4f000 + 852022
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 5 Foundation 0x27ac3386 0x279f2000 + 856966
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 6 libsystem_pthread.dylib 0x34b24e90 0x34b22000 + 11920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 7 libsystem_pthread.dylib 0x34b24e02 0x34b22000 + 11778
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 8 libsystem_pthread.dylib 0x34b22b8c 0x34b22000 + 2956
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 4:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 5 name: PF_AFNetworking
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 5:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34a944f0 0x34a93000 + 5360
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_kernel.dylib 0x34a942e4 0x34a93000 + 4836
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 CoreFoundation 0x26d79b4e 0x26cae000 + 834382
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 CoreFoundation 0x26d780f4 0x26cae000 + 827636
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 CoreFoundation 0x26cc661c 0x26cae000 + 99868
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 5 CoreFoundation 0x26cc642e 0x26cae000 + 99374
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 6 Foundation 0x279fe428 0x279f2000 + 50216
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 7 Foundation 0x27a4c8e8 0x279f2000 + 370920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 8 myAppName 0x001317ee 0x4f000 + 927726
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 9 Foundation 0x27ac3386 0x279f2000 + 856966
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 10 libsystem_pthread.dylib 0x34b24e90 0x34b22000 + 11920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 11 libsystem_pthread.dylib 0x34b24e02 0x34b22000 + 11778
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 12 libsystem_pthread.dylib 0x34b22b8c 0x34b22000 + 2956
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 6 name: com.apple.NSURLConnectionLoader
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 6:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34a944f0 0x34a93000 + 5360
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_kernel.dylib 0x34a942e4 0x34a93000 + 4836
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 CoreFoundation 0x26d79b4e 0x26cae000 + 834382
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 CoreFoundation 0x26d780f4 0x26cae000 + 827636
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 CoreFoundation 0x26cc661c 0x26cae000 + 99868
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 5 CoreFoundation 0x26cc642e 0x26cae000 + 99374
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 6 CFNetwork 0x2687f3da 0x26803000 + 508890
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 7 Foundation 0x27ac3386 0x279f2000 + 856966
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 8 libsystem_pthread.dylib 0x34b24e90 0x34b22000 + 11920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 9 libsystem_pthread.dylib 0x34b24e02 0x34b22000 + 11778
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 10 libsystem_pthread.dylib 0x34b22b8c 0x34b22000 + 2956
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 7 name: com.apple.CFSocket.private
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 7:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa808c 0x34a93000 + 86156
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 CoreFoundation 0x26d7e31a 0x26cae000 + 852762
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b24e90 0x34b22000 + 11920
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 3 libsystem_pthread.dylib 0x34b24e02 0x34b22000 + 11778
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 4 libsystem_pthread.dylib 0x34b22b8c 0x34b22000 + 2956
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 8:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 9:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 10:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 11:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 12:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0 libsystem_kernel.dylib 0x34aa89cc 0x34a93000 + 88524
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 1 libsystem_pthread.dylib 0x34b22ea8 0x34b22000 + 3752
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 2 libsystem_pthread.dylib 0x34b22b80 0x34b22000 + 2944
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Thread 0 crashed with ARM Thread State (32-bit):
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: r0: 0x0056c500 r1: 0x00000000 r2: 0x156a7a00 r3: 0x00000fff
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: r4: 0x3713cd40 r5: 0x349de338 r6: 0x352bfca8 r7: 0x005622e8
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: r8: 0x155c4610 r9: 0x156a8000 r10: 0x155c4610 r11: 0x156cb5f0
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: ip: 0x37154124 sp: 0x005622d4 lr: 0x349c6d49 pc: 0x349c6d48
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: cpsr: 0x60000030
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: Binary Images:
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0x4f000 - 0x2eefff myAppName armv7 <8d48834e6e563ba08bd970b675b2c2b1> /var/mobile/Containers/Bundle/Application/DE60F941-317E-49C2-95EA-0F152A117C16/myAppName.app/myAppName
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0x1fed6000 - 0x1fef9fff dyld armv7s <fd3fef9c43c9382e8e46d5d59fb52f86> /usr/lib/dyld
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0x25852000 - 0x259befff AVFoundation armv7s <291c7a621b65396491697e7a7f728b16> /System/Library/Frameworks/AVFoundation.framework/AVFoundation
Sep 22 11:36:32 DeviceName ReportCrash[6766] <Error>: 0x259bf000 - 0x25a1dfff libAVFAudio.dylib armv7s <1b452a7a75513cf9aa82e59feb7eef33> /System/Library/Frameworks/AVFoundation.framework/libAVFAudio.dylib
A lot of lines like the previous one
Take a look at this error messages. It seems an assertion check was failed in iOS SDK.
*** Assertion failure in -[UIFetchContentInBackgroundAction sendResponse:], /SourceCache/BaseBoard/BaseBoard-97/BaseBoard/BSAction.m:221
BUG in client of libdispatch: Assertion failed: Block was run on an unexpected queue
Expected queue: 0x0x3713cd40[com.apple.main-thread]
The assertion did check that the specified block would run on the right dispatch queue. From the assertion message and the stack trace, -[UIFetchContentInBackgroundAction sendResponse:] uses dispatch_assert_queue to check that the application code are using the main queue for the block properly.
So you'd better check your background fetch code that should use the main queue, but your code is using global queue, serial queue or concurrent queue.
In my case the issue was that the completion handler was called twice subsequently
Code with issue
-(void) application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if(condition)
{
completionHandler(UIBackgroundFetchResultNoData);
}
completionHandler(UIBackgroundFetchResultNewData);
}
Fix
-(void) application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
if(condition)
{
completionHandler(UIBackgroundFetchResultNoData);
}
else //fix
{
completionHandler(UIBackgroundFetchResultNewData);
}
}
Please make sure you are not making such a mistake.
I have exactly the same issue depicted by #Kazuki Sakamoto:
2014-10-16 01:37:05.284 musiXmatch[1589:400275] *** Assertion failure in -`[UIFetchContentInBackgroundAction sendResponse:], /SourceCache/BaseBoard/BaseBoard-97/BaseBoard/BSAction.m:221`
Adding a
dispatch_async(dispatch_get_main_queue(), ^{
Fixed the issue!

EKCalendar title crashing app (MonoTouch.EventKit.EKCalendar.set_Title)

I have a problem with EKCalendar from MonoTouch.EventKit. Application is crashing when I try to set a title by a property. It doesn't occur every time, just twice. Here are a fragment of my logs:
Apr 29 16:49:19 iPad[973] <Error>: Stacktrace:
Apr 29 16:49:19 iPad[973] <Error>: at <unknown> <0xffffffff>
Apr 29 16:49:19 iPad[973] <Error>: at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend_IntPtr (intptr,intptr,intptr) <0xffffffff>
Apr 29 16:49:19 iPad[973] <Error>: at MonoTouch.EventKit.EKCalendar.set_Title (string) [0x0001b] in /Developer/MonoTouch/Source/monotouch/src/EventKit/.pp-EKCalendar.g.cs:134
Apr 29 16:49:19 iPad[973] <Error>: at OverwriteEKCalendar (MonoTouch.EventKit.EKCalendar) [0x00022] in \Services\Calendar\EKCalendarTouch.cs:229
Apr 29 16:49:19 iPad[973] <Error>: at Services.Calendar.CalendarService.OverwriteCalendar
Code is very simple:
public void OverwriteEKCalendar(EKCalendar calendar)
{
if (this.CGColor != null)
{
calendar.CGColor = this.CGColor.ToCGColor();
}
calendar.Title = this.Title;
}
Do you have any idea what's going on?

Error when trying to merge two UIImages into an UIImageView

I'm trying to merge a couple photos (UIImages) into a Image View. I'm using this method:
- (UIImage *) addImageToImage:(UIImage *)img withImage2:(UIImage *)img2{
CGSize size = CGSizeMake(finalPhoto.image.size.width, finalPhoto.image.size.height);
UIGraphicsBeginImageContext(size);
CGPoint pointImg1 = CGPointMake(0,0);
[img drawAtPoint:pointImg1];
CGPoint pointImg2 = CGPointMake(0,0);
[img2 drawAtPoint: pointImg2];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
The problem is that it cant make the merge because it doesn't have the corrects points (I guess...) Here is the log:
Jan 17 09:35:20 <Error>: CGContextSaveGState: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextSetBlendMode: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextSetAlpha: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextTranslateCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextScaleCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextConcatCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextDrawImage: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextRestoreGState: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextSaveGState: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextSetBlendMode: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextSetAlpha: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextTranslateCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextScaleCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextConcatCTM: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextDrawImage: invalid context 0x0
Jan 17 09:35:20 <Error>: CGContextRestoreGState: invalid context 0x0
This problems happens on iOS 6 and iOS 7. Is there a posible solution? Thanks.
Use below code:
- (UIImage *) addImageToImage:(UIImage *)img withImage2:(UIImage *)img2{
//merge two images for this code
CGSize newSize = CGSizeMake(512,512); // Set your bottom image size
UIGraphicsBeginImageContext(newSize);
// Use existing opacity as is
[img drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];///1st image set frame
// Apply supplied opacity if applicable
[img2 drawInRect:CGRectMake(165,332,165,120) blendMode:kCGBlendModeNormal alpha:1];//2nd image set frame with alpha value
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage; //return UIImage
}
My guess is that your images are nil pointers, so the rectangle you're using to create your context is empty. Check the value of size before you create your context:
NSLog(#"Size = %#", NSStringFromCGSize(size));

Resources