I'm working on a cocos2d project on iOS6 and it crash time to time while I'm trying to share something on twitter.
- It only crashes on physical device (iOS 6.1.3)
- It runs without any problems on simulator (iOS 6.1)
The problem arises when [twitterViewController addImage:] is used- I'm using ARC
- Update: the problem is the \n character on body
When I call shareOnTwitter function, it opens the twitter share. I can close or post and it dismiss the view fine. But the second, third or even more times you press the button it crash with EXC_BAD_ACCESS.
With Enable Zombie Objects I get this error:
[SLTwitterComposeViewController respondsToSelector:]: message sent to deallocated instance
It does not crash on any particular line on my code.
Stack:
libobjc.A.dylib`objc_msgSend:
0x3ad3b5a0: teq.w r0, #0
0x3ad3b5a4: beq 0x3ad3b5e6 ; objc_msgSend + 70
0x3ad3b5a6: push.w {r3, r4}
0x3ad3b5aa: ldr r4, [r0]
0x3ad3b5ac: lsr.w r9, r1, #2
0x3ad3b5b0: ldr r3, [r4, #8] <-------- Thread 1: EXC_BAD_ACCESS
0x3ad3b5b2: add.w r3, r3, #8
0x3ad3b5b6: ldr r12, [r3, #-8]
0x3ad3b5ba: and.w r9, r9, r12
0x3ad3b5be: ldr.w r4, [r3, r9, lsl #2]
Code:
- (void)shareOnTwitter {
UIImage *renderedImage = ...;
NSString *text = ...;
SLComposeViewController *twitterViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterViewController setInitialText:text];
[twitterViewController addImage:renderedImage];
[twitterViewController addURL:[NSURL URLWithString:kAPPURL]];
[twitterViewController setCompletionHandler:^(SLComposeViewControllerResult result){
switch (result) {
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
break;
default:
break;
}
[[CCDirector sharedDirector] dismissViewControllerAnimated:YES completion:nil];
}];
[[CCDirector sharedDirector] presentViewController:twitterViewController animated:YES completion:nil];
}
Thanks for your help!
UPDATE:
The problem is solved when I comment the line that adds the image:
//[twitterViewController addImage:renderedImage];
Which made me doubt about my render image function, so I replaced the line with:
[twitterViewController addImage:[UIImage imageNamed:@"[email protected]"]];
And the problem is noticeable once again. Weird right?